htmlpdf-generationnuget-packagedinktopdf

Page Break with DinkToPDF


I'm using the DinkToPDF NuGet and I'd like to add a new page break after the first page. Is this possible? I know it would have to be done within the HTML, but providing an element with 100% height does not have the desired effect.


Solution

  • While it is not perfect, with these settings:

    var globalSettings = new GlobalSettings
    {
        ColorMode = ColorMode.Color,
        Orientation = Orientation.Portrait,
        PaperSize = PaperKind.A4,
        Margins = new MarginSettings { Top = 10 },
        DocumentTitle = "PDF Report"
    };
    
    var objectSettings = new ObjectSettings
    {
        PagesCount = true,
        HtmlContent = html.ToString(),
        //Page = "https://code-maze.com/", USE THIS PROPERTY TO GENERATE PDF CONTENT FROM AN HTML PAGE
        WebSettings = { DefaultEncoding = "utf-8" }, //, UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
        HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
        FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
    };
    

    I can use an HTML file with a series of DIVs set like this to fit them to 1 page size each:

    <div style="height: 1308px; overflow:hidden;">