We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to you center and align right on Pdf header template?

Thread ID:





120259 Sep 15,2015 08:02 AM UTC Sep 16,2015 06:14 AM UTC Xamarin.Forms 2
Tags: PDF
Anita Sheffield
Asked On September 15, 2015 08:02 AM UTC

I have created a pdf, and find I can center and right-align text by using the PdfTextElement and Draw with a rectangleF. But when I created a PdfPageTemplateElement to group the items into a header, I cannot center and align-right the text. How do I do this? I need to center a title and right-align and left-align a few PdfTextElements.

this works for items drawn directly on page:
PdfStringFormat strformat = new PdfStringFormat () { WordWrap = PdfWordWrapType.Word, LineLimit = true, Alignment = PdfTextAlignment.Center };
PdfTextElement txtElement = new PdfTextElement(vm.SubmitAllData.TestSheets [vm.SubmitAllData.CurrentTestsheet].printname)
            { Font = FontResources.PdfHeaderFont, Brush= blackbrush, StringFormat = strformat };
PdfLayoutResult result = txtElement.Draw(page, new RectangleF(0, 70, doc.PageSettings.Width, 30));

How do I draw it on the header? I tried this but it doesn't center the text:

RectangleF rect = new RectangleF(0, 0, doc.PageSettings.Width, headheight);
PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
PdfGraphics hg = header.Graphics;

. . .
txtElement.Draw (hg, new PointF(0, 70));

Anita Sheffield
Replied On September 15, 2015 08:53 AM UTC

I figured this out - Using the .Draw method., pass the header.Graphics, and if the PdfTextElement is set to Center - it centers at the position PointF, if it is set to right justify - PointF is used as the right side of the text.
txtElement.Draw (hg, new PointF(0, 70));

Karthik Krishnaraj [Syncfusion]
Replied On September 16, 2015 06:14 AM UTC

Hi Anita,
Thank you for contacting Syncfusion support,
We are happy to know that issue has been resolved at your end, please let me know if you have any other queries.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon