Add HTML footer only for first page with pagination

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v11)  /  Add HTML footer only for first page with pagination

DynamicPDF CoreSuite for .NET (v11) Forum

Is their a way to add HTML footer with pagination for first page? other page only will have right side page number.
I am using HtmlArea to pass complete HTML.

I am checking product is able to fulfill our requirement or not? so your help will great help to us. 
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
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

All times are US Eastern Standard time. The time now is 8:42 PM.