使用DinkToPDF进行分页

时间:2019-03-20 15:05:14

标签: html pdf-generation nuget-package

我正在使用DinkToPDF NuGet,我想在第一页之后添加一个新的分页符。这可能吗?我知道这必须在HTML内完成,但是为元素提供100% height并没有达到预期的效果。

1 个答案:

答案 0 :(得分:0)

使用以下设置虽然并不完美:

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" }
};

我可以使用具有一系列DIV的HTML文件,像这样将它们设置为每个页面大小为一个页面:

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