How to Page Break HTML Content in HTML Renderer

Darshaka picture Darshaka · Jun 7, 2017 · Viewed 7k times · Source

I have a project where HTML code is converted to a PDF using HTML Renderer. The HTML code contains a single table. The PDF is displayed but the issue is that the contents of the table are cut off at the end. So is there any solution to the problem?enter image description here

PdfDocument pdf=new PdfDocument();

            var config = new PdfGenerateConfig()
            {
                MarginBottom = 20,
                MarginLeft = 20,
                MarginRight = 20,
                MarginTop = 20,
            };
            //config.PageOrientation = PageOrientation.Landscape;
            config.ManualPageSize = new PdfSharp.Drawing.XSize(1080, 828);

            pdf = PdfGenerator.GeneratePdf(html, config);

            byte[] fileContents = null;
            using (MemoryStream stream = new MemoryStream())
            {
                pdf.Save(stream, true);
                fileContents = stream.ToArray();
                return new FileStreamResult(new MemoryStream(fileContents.ToArray()), "application/pdf");
            }

Answer

HTMLRenderer should be able break the table to the next page.
See also:
https://github.com/ArthurHub/HTML-Renderer/pull/41

Make sure you are using the latest version. You may have to add those CSS properties.

Also see this answer:
https://stackoverflow.com/a/37833107/162529