Search code examples
c#openhtmltopdf

How to add last page in PDF?


I am using OpenHtmlToPdf. Is it possible to add 1 page as last page of document. I have read all document but found noting.

The following is the same code to generate pdf document.

 string html = Utils.ReadFile(@"C:\inetpub\wwwroot\pdf.html");
        html = html.Replace("###BODY###", "DYNAMIC CONTENT");
        var pdf = Pdf
            .From(html)
            .OfSize(PaperSize.A4)
            .WithTitle("PDF Report With Logo")
            .WithoutOutline()
            .WithObjectSetting("header.htmlUrl", "http://localhost/header.htm")
            .WithObjectSetting("footer.htmlUrl", "http://localhost/footer.htm")
            .WithObjectSetting("web.defaultEncoding", "utf-8")                
            .Landscape()
            .Comressed()
            .Content();

Solution

  • If your last page is also based on html, you can add a page brake to your final html and then add page itself:

    html += $"<div style=\"page-break-after: always;\"></div>{your_last_page}";