1

I am using wkhtmltopdf 0.12.6 with asp.net core and deployed it in Azure Linux. I want to show different header for the cover page. But when I generate, page header is not showing for the cover page. Page header has been removed automatically.

How to add page for the cover page? The following is NReco code. But if the solution has been found from wkhtmltopdf, then it is fine.

NReco code Code:

 public class PdfService : IPdfService
    {
        public HtmlToPdfConverter HtmlToPdf { get; }
        public PdfService(
            HtmlToPdfConverter htmlToPdf)
        {
            HtmlToPdf = htmlToPdf;
            SetupConverter();
        }
        
        public byte[] ToPdf(string htmlContent, string coverpage)
        {
            return HtmlToPdf.GeneratePdf(htmlContent, coverpage);
        }

        public byte[] ToPdf(string htmlContent, string coverpage, string header)
        {
            HtmlToPdf.PageHeaderHtml = header;
            return ToPdf(htmlContent, coverpage);
        }
}
Jeeva J
  • 3,173
  • 10
  • 38
  • 85

1 Answers1

0

In wkhtmltopdf page header/footer are NOT applied to the 'cover' page, this is by design and this is normal behavior.

If you want to apply different page header/footer for the first page you shouldn't use wkhtmltopdf's cover page; instead of that you can use HtmlToPdfConverter.GeneratePdfFromFiles(WkHtmlInput[], String, String) method where you can provide separate page header/footer for each input HTML. Please note that this method is a part of 'advanced API' and it can be used only if you have a license key.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • I have tried this. But toc is generating in the first page. The cover page is coming after toc. The cover page should come first and then toc and then content – Jeeva J Apr 21 '21 at 09:26