BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
I instantly used this logic from my previous thread:
Though it seems to fix the footer issue, the same logic has failed to fix he issue in header and I cannot think of a reason to why it is not generating the header properly .
Code segment is shown below:
private PdfPageTemplateElement HeaderHTMLtoPDFSyncfusion(string headerHtml, HeaderFooterMargin headerMargin, PdfPageOrientation pdfPageOrientation, SizeF pdfPageSize, Manifest manifest)
{
try
{
var headerMarginLeft = headerMargin != null ? headerMargin.Left : 0;
var headerMarginRight = headerMargin != null ? headerMargin.Right : 0;
var headerMarginHeight = headerMargin != null ? headerMargin.Height : 0;
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
blinkConverterSettings.CommandLineArguments.Add("--no-sandbox");
blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox");
blinkConverterSettings.PdfPageSize = pdfPageSize;
blinkConverterSettings.Margin.Left = headerMargin.Left;
blinkConverterSettings.Margin.Right = headerMargin.Right;
blinkConverterSettings.Orientation = pdfPageOrientation;
blinkConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(1024, 0);
blinkConverterSettings.EnableJavaScript = manifest.EnableJavaScript;
htmlConverter.ConverterSettings = blinkConverterSettings;
//Convert URL to PDF
using (Syncfusion.Pdf.PdfDocument document = htmlConverter.Convert(headerHtml, ""))
{
RectangleF bounds = new RectangleF();
if (pdfPageOrientation.ToString() == "Portrait")
{
bounds = new RectangleF(headerMarginLeft, 0, pdfPageSize.Width - (headerMarginRight + headerMarginLeft), headerMarginHeight);
}
else
{
bounds = new RectangleF(headerMarginLeft, 0, pdfPageSize.Height - (headerMarginRight + headerMarginLeft), headerMarginHeight);
}
//RectangleF bounds = new RectangleF(Math.Abs(2 * headerMarginLeft + 4), 0, Math.Abs(pdfPageSize.Width) + (Math.Abs(2 * headerMarginRight + 4) + Math.Abs(2 * headerMarginLeft + 8)), Math.Abs(headerMarginHeight));
//RectangleF bounds = new RectangleF(headerMargin.Left, 0, pdfPageSize.Width - headerMargin.Right, headerMargin.Height);
PdfPageTemplateElement header = new PdfPageTemplateElement(bounds);
header.Graphics.DrawPdfTemplate(document.Pages[0].CreateTemplate(), bounds.Location, pdfPageSize);
return header;
}
}
catch (Exception ex)
{
throw new Exception(ex?.Message);
}
}
Hi Duminda,
Thank you for reaching out to Syncfusion support.
We are unable to reproduce the reported issue on our end. We suspect the reported issue may occur for the particular document. However, we have created the sample for adding the PDF header and footer while converting the HTML to a PDF document. Please find below.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/HTMLtoPDF_Header_Footer-248083555
Kindly try the provided sample with your input HTML file/URL and let us know the result. If you are still facing the issue, we kindly request you to share the modified sample with input documents, package name, and package version to replicate the same problem on our end. This information will be more helpful for us to analyze and provide you with a prompt solution.
Regards,
Karmegam