2

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.

Adnan Sharif
  • 919
  • 7
  • 17
Matt W
  • 11,753
  • 25
  • 118
  • 215

2 Answers2

2

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;">
Matt W
  • 11,753
  • 25
  • 118
  • 215
  • 2
    Finally found the answer: https://stackoverflow.com/questions/55419335/separating-page-breaks-with-dinktopdf/55628424?noredirect=1#comment97980841_55628424 – Matt W Apr 12 '19 at 11:14
0

I'm using the https://github.com/rdvojmoc/DinkToPdf NuGet; we can control page breaking using CSS Styling

table {
 page-break-inside: auto
}

tr {
 /*page-break-inside: avoid;*/
 page-break-after: always;
 display: table-row-group;
}

thead {
 display: table-header-group;
}

tfoot {
  display: table-footer-group;
  display: table-row-group;
 }
aamir
  • 16
  • 1
  • 5