我知道可以使用C# API在页眉/页脚中呈现"Page 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);..but我更愿意使用以下方法在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;of &P;呈现在页脚中。
发布于 2016-05-19 09:22:47
我对此做了短暂的努力。为了其他通过搜索发现这一点的人,诀窍是当您添加HTML元素时,它必须是一个HtmlToPdfVariableElement而不是一个HtmlToPdfElement。
HtmlToPdfVariableElement footerHtml = new HtmlToPdfVariableElement(pdfOptions.DocumentFooterHtmlString, pdfOptions.BaseUrl);
footerHtml.FitHeight = true;
pdfConverter.PdfFooterOptions.AddElement(footerHtml);发布于 2014-12-01 18:36:01
看来你能做到。请参阅HTML.aspx
在示例代码中,Evo提供了他们使用HtmlToPdfVariableElement的方法。
https://stackoverflow.com/questions/18608657
复制相似问题