2017-06-04 13 views
1
Suppose I have a HTML that have some heading & text like: 

Heading 1 
text...... 

Heading 2 
text..... 

Heading 3 
text..... 

现在我要打印PDF这个模板,内容要知道页码,我必须添加索引页实际上与航向参考页码。意味着打印出来应该是这样的。ExpertPDF - 如何基于打印输出过程中HTML

Heading 1 ....... 1 [page number] 
Heading 2 ....... 2 
Heading 3 ....... 3 

Heading 1 
text...... 

Heading 2 
text..... 

Heading 3 
text..... 

所以在这里,我想知道,如何根据在HTML文本知道页码,就像标题1属于哪一页为别人数&。

Any suggestion or idea really appreciated. 

回答

0

pdfConverter.PdfFooterOptions.PageNumberTextFontSize = 10; pdfConverter.PdfFooterOptions.ShowPageNumber = true;

它的这种方法的体内完成: -

private void AddFooter(PdfConverter pdfConverter) 
{ 
string thisPageURL = HttpContext.Current.Request.Url.AbsoluteUri; 
string headerAndFooterHtmlUrl = thisPageURL.Substring(0, thisPageURL.LastIndexOf('/')) + "/HeaderAndFooterHtml.htm"; 

//enable footer 
pdfConverter.PdfDocumentOptions.ShowFooter = true; 
// set the footer height in points 
pdfConverter.PdfFooterOptions.FooterHeight = 60; 
//write the page number 
pdfConverter.PdfFooterOptions.TextArea = new TextArea(0, 30, "This is page &p; of &P; ", 
new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10, System.Drawing.GraphicsUnit.Point)); 
pdfConverter.PdfFooterOptions.TextArea.EmbedTextFont = true; 
pdfConverter.PdfFooterOptions.TextArea.TextAlign = HorizontalTextAlign.Right; 
// set the footer HTML area 
pdfConverter.PdfFooterOptions.HtmlToPdfArea = new HtmlToPdfArea(headerAndFooterHtmlUrl); 
pdfConverter.PdfFooterOptions.HtmlToPdfArea.EmbedFonts = cbEmbedFonts.Checked; 
} 

更多细节 http://www.expertpdf.net/expertpdf-html-to-pdf-converter-headers-and-footers/

+0

不,我不想在页脚中注入页码,我想知道基于HTML中某些文本的页码。就像在HTML中我有文字ABC&我想知道这个ABC在打印输出时属于哪个页码。 – John

+0

嗨,试试这个链接https://forums.asp.net/t/1902490.aspx?How+to+set+and+get+ASP+net+MVC+Hidden+Field+values – bhagi

0

这实际上是ExpertPDF必须提供特定的功能,使一个相当棘手的问题,请参见本页面可能。

我的解决方案(不是expertpdf)为此首先计算PDF的布局,获取要在每个页面的索引中使用的文本,然后计算索引页面的布局。然后,我可以对页面(包括索引页)进行编号,然后更新索引中的页码。这是处理跨越多个页面的模板页面的唯一方法,索引文本包含的内容多于一个单行和跨越多个页面的索引。