Can you share the solution please, I need to implement this, I mean how can I center a text in the rectangle
This was an old post, using a 2015 version of syncfusion, but it is still working code for us. We are also adding a logo on the left side of the header. I hope this helps.
RectangleF rect = new RectangleF(0, 0, doc.PageSettings.Width, headheight);
PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
try
{
PdfGraphics hg = header.Graphics;
PdfSolidBrush blackbrush = new PdfSolidBrush(ColorResources.pdfblack);
PdfStringFormat strformat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle) { WordWrap = PdfWordWrapType.Word, LineLimit = true };
if (logoImg != null)
{
hg.DrawImage(logoImg, 10, 0, 140, 40f);
}
PdfTextElement txtElement = new PdfTextElement("Inventory Report For Location: " + location)
{ Font = FontResources.PdfHeaderFont, Brush = blackbrush, StringFormat = strformat };
txtElement.Draw(hg, new PointF(doc.PageSettings.Width / 2, 40));