Evo Pdf - HTML 中的页码编号

  • 本文关键字:编号 Pdf HTML Evo evopdf
  • 更新时间 :
  • 英文 :


我知道可以使用 C# API 在页眉/页脚中呈现"Page X of Y",如下所示:

//write the page number
TextElement footerText = new TextElement(0, pdfConverter.PdfFooterOptions.FooterHeight - 15, "This is page &p; of &P;  ",
    new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10, System.Drawing.GraphicsUnit.Point));
footerText.EmbedSysFont = true;
footerText.TextAlign = HorizontalTextAlign.Right;
pdfConverter.PdfFooterOptions.AddElement(footerText);

..但我宁愿使用以下方法直接在 HTML 中定位和设置它:

 HtmlToPdfElement footerHtml = new HtmlToPdfElement(pdfOptions.DocumentFooterHtmlString, pdfOptions.BaseUrl);
 footerHtml.FitHeight = true;
 pdfConverter.PdfFooterOptions.AddElement(footerHtml);

其中pdfOptions.DocumentFooterHtmlString看起来像这样:

<div class="clearfix">
    <span class="pull-right">This is page &p; of &P;</span>
</div>

这是可能的吗?如果我尝试这个,我只会得到:这是页脚中呈现的页面&p;和P。

我为此苦苦挣扎了一下。为了其他通过搜索找到它的人,诀窍是当你添加HTML元素时,它必须是HtmlToPdfVariableElement而不是HtmlToPdfElement。

HtmlToPdfVariableElement footerHtml = new    HtmlToPdfVariableElement(pdfOptions.DocumentFooterHtmlString, pdfOptions.BaseUrl);
footerHtml.FitHeight = true;
pdfConverter.PdfFooterOptions.AddElement(footerHtml);

看起来你可以做到这一点。请参阅 http://www.evopdf.com/demo/PDF_Creator/Headers_and_Footers/Page_Numbers_in_HTML.aspx

在 Evo 提供的示例代码中,他们使用 HtmlToPdfVariableElement。

最新更新