Header is not repeating in pdf generation for second page in C# code

182 views Asked by At

'I am using below code for header template and it's breaking in the second page. Attached screen shot below.

[1st page header looks good] (https://i.stack.imgur.com/9lfZI.png)

[2nd page header is overlapping with text] (https://i.stack.imgur.com/4oIDK.png)

         ` var marginOptions = new MarginOptions();`

            marginOptions.Top = "100px";
            marginOptions.Bottom = "100px";
            marginOptions.Left="10px";
            marginOptions.Right="10px";`

            var pdfOptions = new PuppeteerSharp.PdfOptions`
            {
                `HeaderTemplate = "<div style='width: 100%; page-break-inside: avoid; display: block;' class='headerpage'><div style='width: 33.3%;float: left;text-align: left;'></div><div style='width: 33.3%;float: right;text-align: right;'></div><div style='width: 33.3%;float: right;text-align: left;'><h2 style='font-size: 50px;font-family: Times;color: #00008B;margin: 0px !important;right: 8px;'>Portfolio</h2></div>" +
                "<hr style='border: none;background-color: #00008B;display: block;width: 85%;border-top: solid 5px #00008B;'>" +
                "<div style='width: 33.3%;float: left;text-align: left;'></div><div style='width: 33.3%;float: right;text-align: right;'></div><div style='width: 33.3%;float: right;text-align: left;'><h2 style='font-size: 50px;font-family: Times;color: #00008B;margin: 0px !important;right: 8px;'>Billing</h2></div></div>",
                DisplayHeaderFooter = true,
                // Format= PaperFormat.A4,
                MarginOptions =  marginOptions,`
            };
           
            var options = new LaunchOptions
            {
                Headless = true
            };

            Console.WriteLine("Downloading chromium");

            using var browserFetcher = new BrowserFetcher();
            await browserFetcher.DownloadAsync();
            
            using var browser = await Puppeteer.LaunchAsync(options);
            using var page = await browser.NewPageAsync();

           string html = sbFinal.ToString(); //Here my pdf generation html string. It can be 100 pages of data.
           await page.SetContentAsync(html);            

           await page.PdfAsync("D:\\PDF\\DOTNET PDF Report Generation\\forStylingJagan\\" + "Invoice", pdfOptions);

I am expecting that the second should align same as like first image and text should not be overlap.`

0

There are 0 answers