- Home
- Forum
- Xamarin.Forms
- How to you center and align right on Pdf header template?
How to you center and align right on Pdf header template?
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));
txtElement.Draw (hg, new PointF(0, 70));
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.
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));
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));
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));
- 4 Replies
- 3 Participants
-
AS Anita Sheffield
- Sep 15, 2015 08:02 AM UTC
- Apr 10, 2023 03:46 PM UTC