How to have dynamic header template in Html to PDF conversion

We are using Syncfusion html to pdf conversion library for generating PDFs out of HTML. 

We are using  PdfPageTemplateElement class to generate as header object for the PDF.

For some of the generated pages, we want to have dynamic header object, how can we achieve that using Syncfusion PDF to HTML generation


Edit: To be specific, if i have 100 pages of html, on some of the pages of generated PDF, i want a text to appear in the header.  Whether the text should appear on PDF header depends on the content of the page


-Balaji


12 Replies

KS Karmegam Seerangan Syncfusion Team April 2, 2024 01:18 PM UTC

Hi Balaji,


Thank you for reaching out to Syncfusion support.

Our HTML converter internally uses the Blink rendering engine. It utilizes a Chrome headless browser for converting HTML to PDF. 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 and print preview. Our converter replicates this same behavior.

 

We have analyzed the reported issue on our end. Currently, we don't have support to add dynamic Header on particular pages while converting HTML to PDF documents. We internally set the header on every page of the output document. However, we have workaround solution to remove the first page header only. Please refer to the below documentation.

 

https://support.syncfusion.com/kb/article/11871/how-to-add-pdf-header-and-footer-while-converting-html-to-pdf-document

https://support.syncfusion.com/kb/article/7897/how-to-skip-headerfooter-for-html-page-to-winforms-pdf


Regards,


Karmegam



BA bala April 3, 2024 06:47 AM UTC

Thanks for your reply


How do i edit Header template in already generated PDF and updated a text(header template) in that PDF, do you have an example for that?


-Balaji



KS Karmegam Seerangan Syncfusion Team April 3, 2024 04:11 PM UTC

We can achieve the reported behavior by removing the existing header using the redaction method and adding the new text. However, we have attached the console sample and documentation for your reference.

 

Working with Redaction |Syncfusion

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Edit_Pdf_Header_2-1053299190

 

Kindly try the sample on our end and let us know the result. If you are still facing issues, we kindly request you to share the modified sample, input HTML with resources, complete code snippet, and environment details to check the reported issue on our end. This information will be more helpful for us to analyze and provide you with a prompt solution.




BA bala April 18, 2024 07:50 AM UTC

Hi the above solution almost satisfies my requirement, when doing analysis, if i used the below library

Syncfusion.Pdf.Imaging.Net.Core​, will it ask for license? when used it, the header showed generated with syncfusion trial library

 i have other syncfusion licenses for generating html to pdf via blink libraries like  Syncfusion.HtmlToPdfConverter.Blink.Net.Core.Linux


Thanks

Balaji



KS Karmegam Seerangan Syncfusion Team April 19, 2024 02:56 PM UTC

To prevent trial watermarks from appearing on PDF documents, it is recommended to register a valid license before generating the pdf document. For further details on how to register the license key in your application, please refer to the following user guide documentation.

Overview of Syncfusion license generation - Syncfusion

Overview of Syncfusion license registration - Syncfusion

Overview of Syncfusion license and unlock keys - Syncfusion



BA bala April 20, 2024 04:20 AM UTC

Hi


Thanks for the reply

I had syncfusion license, do i need to purchase/buy this library Syncfusion.Pdf.Imaging.Net.Core?



KS Karmegam Seerangan Syncfusion Team April 22, 2024 04:30 PM UTC

Currently, we are checking on this and will update with further details on April 23, 2024.



KS Karmegam Seerangan Syncfusion Team April 23, 2024 12:53 PM UTC

We have checked the reported issue on our end. If you already have a Syncfusion license for the Syncfusion.HtmlToPdfConverter.Blink.Net.Core.Linux package, you can also use it for the Syncfusion.Pdf.Imaging.Net.Core package. However, all Syncfusion packages must be installed to the major version of the Syncfusion package, such as v22.2.*.

 

When you are using Syncfusion assemblies\NuGet packages from nuget.org or a trial installer, you should generate and register the corresponding version and platform license key in your application to avoid a trial license warning. 

 

Syncfusion license keys are major version and platform-specific and please, ensure that all the referenced Syncfusion assemblies\NuGet packages are all on the same version as the license key’s version in your project. 

 

Refer to the below KB article to know which version license key should use in the application,

https://support.syncfusion.com/kb/article/7865/which-version-syncfusion-license-key-should-i-use-in-my-application

Please, ensure that all the referenced Syncfusion assemblies\NuGet packages versions are all on the same version as the license key’s version in your project.

Refer to this link for generating the license key,

https://help.syncfusion.com/common/essential-studio/licensing/how-to-generate

 

Refer to this link for registering the license key,

https://help.syncfusion.com/common/essential-studio/licensing/how-to-register-in-an-application

Note: If you are using any template file for generating the PDF document, please ensure that the original template file doesn’t have any license trial warning

Sometimes, old Syncfusion packages might be referred from the NuGet cache in the project.

 

So, could you please try cleaning your project, clearing the NuGet cache from both the “%userprofile%” folder and the NuGet installed location, deleting the bin\obj folders, and rebuilding your application, then check whether it resolves the issue?

If the reported issue is still not resolved,  please share the following details to check the issue further from our side, 

  1. List of Syncfusion NuGet packages\assemblies used and its version,
  2. License key used in the application,
  3. Screenshot of license key registered place,
  4. Target Framework and Platform of your application,
  5. Screenshot of the issue.

Please let us know if you have any concerns.

 



SS Sumrender Singh January 29, 2025 04:17 PM UTC

Hello,

Is there any support for adding a dynamic header?
Or can you guide me to any workaround for this?

My use case is that I have a header which is generated dynamically and might get lengthy, so I cannot hardcode any padding or margin to create space for header and footer.

I am thinking of somehow getting header height and then add this property in the html body.

@media print {
@page {
margin-top: {HEIGHT_OF_HEADER};
}
}




AM Arumugam Muppidathi Syncfusion Team January 30, 2025 02:03 PM UTC

Hi Sumrender,


We have reviewed your query, and after further analysis, we found that you can determine the height of the HTML header using the GetHtmlBounds() method. This method allows you to retrieve the dimensions (width and height) of the HTML content based on the current settings, such as the viewport width and scale.

 

By using the dynamically calculated height from GetHtmlBounds(), you can set this value as the top margin in the BlinkConverter settings. This approach should address your requirement of handling a dynamic header without the need for hardcoded padding or margins.

 

For further reference, please find the documentation for the GetHtmlBounds() property here:

Converting HTML to PDF | GetHtmlBounds | Syncfusion

 

Additionally, we’ve included a sample along with its corresponding output document for your review.

 

Please try the provided sample on your end and let us know the results. If you encounter any issues, we kindly ask that you provide more details about your specific requirements, along with sample input and HTML documents, as well as the expected output PDF. This will help us better understand your use case and offer a more tailored solution.


Regards,

Arumugam M


Attachment: GetBoundsinHTMLfile_e2cb03b3.zip


SS Sumrender Singh February 3, 2025 06:27 AM UTC

Hi Arumugam,

Thanks for the quick response. I tried using GetHtmlBounds but it is not giving correct height. 


I've attached a link of the POC that I tried. The main requirement is to have dynamic headers, as the headers sometimes get as long as half the page.

https://github.com/sumrender/syncfusion-html-to-pdf-poc



AM Arumugam Muppidathi Syncfusion Team February 5, 2025 04:02 AM UTC

Hi Sumrender,

For better follow-up, We are marking this thread as solved as it is a duplicate of 131142. We request you to follow 131142 for further assistance.

Regards,
Arumugam M


Loader.
Up arrow icon