In addition whenever I try to print some text in templates my text is very blurry. I have attached sample images for you to see. How should I fix this?
- Code: Select all
protected void AddPageHeaderAndFooter(PdfDocument doc, UserInfoModel userInfo, SizeF pageSize)
{
doc.Template.Bottom = new PdfPageTemplateElement(pageSize.Height, _margin.Bottom) { Foreground = true };
for (var pageNumber = 1; pageNumber <= doc.Pages.Count; pageNumber++)
{
// Add Page Footer
doc.Template.Bottom.Graphics.SetTransparency(0.75f);
var footerFormat = new PdfStringFormat(PdfTextAlignment.Center) { LineAlignment = PdfVerticalAlignment.Middle };
var pageCount = $"Page {pageNumber} of {doc.Pages.Count}";
doc.Template.Bottom.Graphics.DrawString(
pageCount,
BodyFont,
PdfBrushes.Black,
pageSize.Height / 2 - BodyFont.MeasureString(pageCount).Width / 2,
doc.Template.Bottom.Height - BodyFont.Height,
footerFormat);
//var format = new PdfStringFormat(PdfTextAlignment.Center) { LineAlignment = PdfVerticalAlignment.Middle };
//var font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Regular));
//var pageNumberLabel = new PdfCompositeField
//{
// AutomaticFields = new PdfAutomaticField[] { new PdfPageNumberField(), new PdfPageCountField() },
// Brush = PdfBrushes.LightGray,
// Font = font,
// StringFormat = format,
// Text = "page {0} of {1}",
// Pen = new PdfPen(Color.LightGray, 0.75f)
//};
//pageNumberLabel.Draw(doc.Template.Bottom.Graphics, pageSize.Height / 2, font.Height);
}
}
BTW, I am not able to perfectly center my footer while using Automatic Fields. Also Using automatic fields method also results in blurry image