0

我正在使用“使用 PDFsharp 的 PDF 的 HTML 渲染器” HtmlRenderer.PdfSharp(版本 1.5.1-beta1)。我正在尝试强制分页。但我无法让它工作。我现在在我的 html 中是这样的:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:v="urn:schemas-microsoft-com:vml"
      xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Test</title>

    <style>
    div { page-break-inside: auto; }
    </style>
</head>
<body style="margin:0; padding:0;" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <div>Page1</div>
    <div>Page2</div>
</body>
</html>

当我将此 html 转换为 PDF 时,两者都div停留在同一页面上。

string contents = File.ReadAllText(@"C:\temp\test.html");
PdfDocument pdf = PdfGenerator.GeneratePdf(contents, PageSize.A4);
pdf.Save(@"C:\temp\pdfsharp.pdf");

如何强制第二个 div 进入新页面?

4

1 回答 1

0

强制分页的唯一已知解决方案是将 html 拆分为多个部分,并为每个 html 部分生成一个页面。Grasher134 在 GitHub 上的解决方案:https ://github.com/ArthurHub/HTML-Renderer/issues/49#issuecomment-251351431

于 2018-10-26T14:19:20.220 回答