Different front page for PDF file in Html to PDF conversion

I'm trying to add a different front page with different margins how can I do this using ASP.NET Core C#



Attachment: WorkOrderNo=248_c20c9e4d_5d2211f0.zip

7 Replies

KS Karmegam Seerangan Syncfusion Team February 19, 2024 03:07 PM UTC

Hi Duminda,


We have checked the reported issue on our end but it is working properly. We can add the Header and Footer by setting the PdfPageTemplateElement as the header and footer using the PdfHeader and PdfFooter property in the BlinkConverterSettings class. Please find the UG documentation,

 

Header and footer,

 

We can change the margin of a PDF document by using the Margin property in the BlinkConverterSettings class.

 

Margin customization

 

Please refer to the below KB documentation,

https://support.syncfusion.com/kb/article/8183/how-to-add-header-on-the-first-page-of-a-pdf-in-c-and-vb-net

https://support.syncfusion.com/kb/article/3881/how-to-add-different-header-for-first-page-in-a-pdf-document

 

Kindly try the provided solution and let us know if you further assistance. 


Regards,

Karmegam




DJ Duminda Jayasuriya February 21, 2024 06:44 AM UTC

I need to fill the first page without borders and I tried this using below code but it doesn't seem to work. 

Is there any difference between WebkitConverterSettings and BlinkConverterSettings, if there's any please explain cause I have done this with WebkitConverterSettings as follows :

WebKitConverterSettings webKitSettings = new WebKitConverterSettings();

//convert header HTML and set its template to webkit settings

//add the header in outside bounds of margin

if (!string.IsNullOrEmpty(header))

{

    webKitSettings.PdfHeader = HeaderHTMLtoPDFSyncfusion(header, margin.HeaderMargin, pdfPageOrientation, pdfpageSize);

}

else

{

    webKitSettings.PdfHeader = HeaderTexttoPDFSyncfusion(headerText, margin.HeaderMargin, pdfPageOrientation, pdfpageSize);

}


if (!string.IsNullOrEmpty(footer))

{

    webKitSettings.PdfFooter = FooterHTMLtoPDFSyncfusion(footer, margin.FooterMargin, manifest.Input.IncludePageNumber, pdfPageOrientation, pdfpageSize);

}

else

{

    webKitSettings.PdfFooter = FooterTexttoPDFSyncfusion(footerText, margin.FooterMargin, manifest.Input.IncludePageNumber, pdfPageOrientation, pdfpageSize);

}


webKitSettings.WebKitViewPort = new Syncfusion.Drawing.Size(1024, 800);

webKitSettings.Orientation = pdfPageOrientation;

webKitSettings.PdfPageSize = pdfpageSize;

webKitSettings.EnableJavaScript = true;

webKitSettings.Margin.Top = margin.HeaderMargin.Height;

webKitSettings.Margin.Bottom = margin.FooterMargin.Height;

webKitSettings.Margin.Left = -20;

webKitSettings.Margin.Top = -20;

htmlConverter.ConverterSettings = webKitSettings;



KS Karmegam Seerangan Syncfusion Team February 21, 2024 11:48 AM UTC

We are unable to replicate the reported issue on our end. We suspect the reported issue may occur for particular input HTML/URL. So we kindly request you to share the input HTML/URL, complete code snippet, package name, and package version with us to replicate the issue on our end. It will be more helpful for us to analyze and provide you with a prompt solution.

The WebKit is a legacy rendering engine and has some known rendering issues and limitations, and some of the advanced Bootstrap CSS styles are not supported. But the Blink rendering engines support the advanced Bootstrap CSS styles. It will preserve the PDF document in the same way as the input HTML/URL is displayed in Chromium-based web browsers such as Chrome print preview. Our converter replicates this same behavior.

 

Please refer to the below documentation for more information about Blink engine,

https://help.syncfusion.com/file-formats/pdf/converting-html-to-pdf




DJ Duminda Jayasuriya February 29, 2024 07:59 AM UTC

Hi,


I need to know how to fill the first two pages of PDF file without any margins or white spaces


Thank you



KS Karmegam Seerangan Syncfusion Team February 29, 2024 01:22 PM UTC

Currently, we are analyzing to add the headers on the first two pages of the pdf document without any margin or white spaces and will update further details on March 4th, 2024.

Meanwhile, we kindly request you to share the input documents with resources, package name, package version, and environment details with us to replicate the same issue on our end. This will be more helpful for us to analyze and provide you prompt solution.



DJ Duminda Jayasuriya March 1, 2024 02:01 AM UTC

Hi,

Your replies doesn't help and doesn't provide a solution . So let me say it clearly again, it is not an issue with the headers or footers. I just need to fill the first page of my PDF document without no margins, white borders or white spaces at the time it is converting from html to PDF with both webkit and blink converters or after being converted to PDF. I just need to know is this feasible and how it can be done.

Thank you.



KS Karmegam Seerangan Syncfusion Team March 1, 2024 01:43 PM UTC

Thank you for your update.


We can convert the HTML to PDF documents without margin using Margin.All is equal to zero in BlinkConverterSettings. It will reflected in all the pages of the document. Please refer the below code snippet.

//Initialize the HTML to PDF converter.

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

//Initialize blink converter settings.

BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();

//Set the margin.

blinkConverterSettings.Margin.All = 0;     

//Assign Blink converter settings to HTML converter.

htmlConverter.ConverterSettings = blinkConverterSettings;

 

If you don't need to set the margin on the first page only, we can able to remove the margin on the first page of the PDF margin using the workaround solution. In that workaround solution, We are using PdfTemplate to remove the margin on the first page only and the remaining page having margins. This process works after the output document generation.

 

However, we are unable to remove the white spaces in between the output document. Because the input HTML looks like it does in Chrome Print Preview, the same result will be generated in our converter. So, please ensure your HTML looks the same in Chrome Print Preview with the same settings that you used in the Blink converter settings.

 

However, we have attached the complete console sample for removing the margins on the first page of the PDF document. Please refer below,

Sample: HTMLtoPDF-First-Page-Margin

 

Kindly try the sample and let us know the result. If the provided solution does not meet your requirements, we kindly request you to share the modified sample with input documents, expected output, issue screenshot, and input documents with us to replicate the same issue on our end. This will be more helpful for us to analyze and assist you further on this.



Loader.
Up arrow icon