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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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 04:53 AM

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 02:14 AM

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.
Thanks,
Karthik.

CONFIRMATION

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.

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.

;