BoldDesk®Customer service software with ticketing, live chat & omnichannel support, starting at $99/mo for unlimited agents. Try for free!
I'm using blink engine to convert html to PDF documents, but I get an issue where my footer seems to be ok in portrait but in landscape the texts in footer stretches and it's not clear. My class for footer is as below:
private PdfPageTemplateElement FooterTexttoPDFSyncfusion(HeaderFooterText footerProperties, HeaderFooterMargin footerMargin, bool includePageNumber, PdfPageOrientation pdfPageOrientation, SizeF pdfPageSize, Manifest manifest)
{
try
{
var footerMarginLeft = footerMargin != null ? footerMargin.Left : 0;
var footerMarginRight = footerMargin != null ? footerMargin.Right : 0;
var footerMarginHeight = footerMargin != null ? footerMargin.Height : 0;
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
blinkConverterSettings.PdfPageSize = new SizeF(pdfPageSize.Width, footerMarginHeight);
blinkConverterSettings.Orientation = pdfPageOrientation;
blinkConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(1024, 0);
blinkConverterSettings.EnableJavaScript = manifest.EnableJavaScript;
float width = pdfPageSize.Width;
RectangleF bounds = new RectangleF(footerMarginLeft, 0, width - (footerMarginRight + footerMarginLeft), footerMarginHeight);
PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
PdfSolidBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
string footerFont = footerProperties.Font.ToLower();
//PdfFontFamily footerFontFamily = new PdfFontFamily();
int footerFontSize;
//switch (footerFont)
//{
// case "courier":
// footerFontFamily = PdfFontFamily.Courier;
// break;
// case "helvetica":
// footerFontFamily = PdfFontFamily.Helvetica;
// break;
// case "timesroman":
// footerFontFamily = PdfFontFamily.TimesRoman;
// break;
// default:
// footerFontFamily = PdfFontFamily.Helvetica;
// break;
//}
if (!string.IsNullOrEmpty(footerProperties.FontSize.ToString()))
{
footerFontSize = footerProperties.FontSize;
}
else
{
footerFontSize = 15;
}
//Syncfusion.Pdf.Graphics.PdfFont font = new PdfStandardFont(footerFontFamily, footerFontSize);
var footerFontFamily = Path.Combine(Environment.CurrentDirectory, "Fonts\\arial-unicode-ms.ttf");
PdfFont font = new PdfTrueTypeFont(footerFontFamily, manifest.Input.PageSetup.FooterText.FontSize);
IFooterComponent footerComponent = new Footer();
string footeralignment = footerProperties.Alignment.ToLower();
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
if (footeralignment == "center")
{
if (includePageNumber)
{
footerComponent = new CenterAlignmentDecorator(footerComponent);
footerComponent.Draw(footer, pdfPageSize, manifest.Input.PageSetup.Orientation);
}
format.Alignment = PdfTextAlignment.Center;
}
else if (footeralignment == "left")
{
if (includePageNumber)
{
footerComponent = new LeftAlignmentDecorator(footerComponent);
footerComponent.Draw(footer, pdfPageSize, manifest.Input.PageSetup.Orientation);
}
format.Alignment = PdfTextAlignment.Left;
}
else if (footeralignment == "right")
{
if (includePageNumber)
{
if (manifest.Input.PageSetup.Orientation.Equals("Portrait"))
{
bounds = new RectangleF(-25, 0, width - (footerMarginRight + footerMarginLeft), footerMarginHeight);
}
else
{
bounds = new RectangleF(-100, 0, width - (footerMarginRight + footerMarginLeft), footerMarginHeight);
}
footer = new PdfPageTemplateElement(bounds);
footerComponent = new RightAlignmentDecorator(footerComponent);
footerComponent.Draw(footer, pdfPageSize, manifest.Input.PageSetup.Orientation);
}
format.Alignment = PdfTextAlignment.Right;
}
else
{
format.Alignment = PdfTextAlignment.Center;
}
footer.Graphics.DrawString(footerProperties.Text, font, brush, bounds, format);
blinkConverterSettings.PdfFooter = footer;
return footer;
}
catch (Exception ex)
{
throw new Exception(ex?.Message);
}
}
Hi Duminda,
We have noticed a difference in the footer text between portrait and landscape PDF documents, but we are unable to replicate the issue. We believe the problem may be specific to a certain document with the input values for the blink converter settings and other variables provided. Therefore, we kindly ask you to share a simplified sample, input HTML/URL with resources, package name, package version, and details about your environment (such as OS platform, bit version, and RAM size) so that we can investigate further and offer a solution promptly.
Regards,
Karmegam
Hi Karmegam,
Requested information as per your request are as follows
Project URL : https://www.syncfusion.com/?utm_source=nuget&utm_medium=listing
Package Name : Syncfusion.HtmlToPdfConverter.Net.Windows
Package Version : 25.1.38
Platform / Version : Windows 11 22H2
bit Version : 64 bit
Ram Size : 32 GB
Regards,
Duminda
Hi Duminda,
On our further validation, in
landscape orientation, if we choose A4 size as input size (595,842) in page
settings, it is reversed in the output PDF document to (842,595). The footer
text stretching issue occurs in landscape orientation due to that. So, instead of width,
we need to set the height of the pdf page size in the PdfPageTemplateElement
bounds to resolve this. We need to replace the page size width using the page
size height in the PdfPageTemplateElement bounds of the footer. We have attached
the code snippet for your reference,
Code snippet:
//Create PDF page template element for footer with bounds. PdfPageTemplateElement footer = new PdfPageTemplateElement(new RectangleF(0, 0, pdfPageSize.Height, 50)); //Create font and brush for header element. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 8); //Create page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(font, PdfBrushes.Black); //Create page count field. PdfPageCountField count = new PdfPageCountField(font, PdfBrushes.Black); var color = Color.FromArgb(179, 179, 179); PdfBrush brush = new PdfSolidBrush(color); //Add the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); //Draw the composite field in footer compositeField.Draw(footer.Graphics, new PointF(250, 20)); return footer; |
Regards,
Sivaram G