Welcome Guest Search | Active Topics | Sign In | Register

HTML to PDF: Different header/margins on first and following pages Options
Harry50
Posted: Friday, March 3, 2023 4:45:30 AM
Rank: Member
Groups: Member

Joined: 7/21/2011
Posts: 12
Hi,

we want to create a multi page PDF from HTML (e.g. invoice) which has a large header (with logo) on the first page and a small header/margin (without logo) on the following pages.
How can this be achieved?

Best regards,
Harry
eo_support
Posted: Friday, March 3, 2023 10:31:17 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,086
Hi,

You can do it this way:

1. Make sure you have enough spare room on the first page for the large header. You can do this either by setting HtmlToPdf.Options.StartPosition or format your HTML so that it has extra padding/margin at the begining;

2. Set HtmlToPdf.Options.HeaderHtmlFormat to the HTML of the small header AND set HtmlToPdf.Options.FirstHeaderFooterPageIndex to 1. This would add the small header to every page except for the first page;

3. Run the conversion. This will give you a result PdfDocument that contains everything you need except for the large header on the first page;

4. Add the large header to the output of the step 3 with code like this:

Code: C#
//Add output to the first page of an existing PdfDocument 
//object (result PdfDocument of step 3). Without this line
//the new output will be appended to end of the file
HtmlToPdf.Options.StartPageIndex = 0;

//Set the page output area to the entire page. Without this
//line the output will be in the main content area
HtmlToPdf.Options.OutputArea = new RectangeF(0, 0, fullPageWidth, fullPageHeight);

//Add the header
HtmlToPdf.ConvertHtml(largeHeaderHtml, doc);


Now you will have your final result PdfDocument object.

Hope this helps. Please let us know if this works for you.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.