Evo Pdf - HTML中的页码编号

时间:2013-09-04 08:13:41

标签: 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>

这是可能的吗?如果我试试这个,我就得到:这是页面&amp; p;在页脚中呈现的&amp; P;

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:3)

看起来你可以这样做。见http://www.evopdf.com/demo/PDF_Creator/Headers_and_Footers/Page_Numbers_in_HTML.aspx

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