Posted by a ceTe Software moderator
Hello,
If you are using HtmlArea to add formatted text to a PDF, then you can use document sectioning and apply a template to it. Please refer to the documentation on document sectioning
here.
You will need to create different templates by adding the required contents using page elements and apply it to the respective section. You can control the positions of page elements using X and Y position coordinates.
Here is a code sample:
Document document = new Document();
string htmlText= File.ReadAllText(@"Input HTMl file path");
HtmlArea htmlArea = new HtmlArea(htmlText, 0, 0, 512, 692);
HeaderFooterTemplate firstTemplate = new HeaderFooterTemplate();
Section firsrtSection = document.Sections.Begin();
firsrtSection.Template = firstTemplate;
Page page1 = new Page();
PageNumberingLabel pageNum1 = new PageNumberingLabel("%%CP%% of %%TP%%", 0, page1.Dimensions.Body.Height, page1.Dimensions.Body.Width, 40);
pageNum1.Align = TextAlign.Center;
firstTemplate.Elements.Add(pageNum1);
page1.Elements.Add(htmlArea);
document.Pages.Add(page1);
htmlArea = htmlArea.GetOverflowHtmlArea();
//Different tamplate for rest of the pages.
HeaderFooterTemplate templateObj = new HeaderFooterTemplate();
PageNumberingLabel pageNum2 = new PageNumberingLabel("%%CP%% in %%TP%%",0, page1.Dimensions.Body.Height, page1.Dimensions.Body.Width, 40);
templateObj.Elements.Add(pageNum2);
Section sectionObj2 = document.Sections.Begin();
sectionObj2.Template = templateObj;
do
{
Page page = new Page();
page.Elements.Add(htmlArea);
document.Pages.Add(page);
htmlArea = htmlArea.GetOverflowHtmlArea();
} while (htmlArea != null);
string output = @"C:Temp\MyDocument.pdf";
document.Draw(output);
Thanks,
ceTe Software Support Team