如何访问page_number和total_pages?

时间:2018-06-21 09:59:18

标签: c# selectpdf

我正在寻找一个HTML模板。我的模板是:

<footer>
  <span class="title">{{ title }}</span> - {{ page_number }} of {{ total_pages }}
</footer>

引擎的名称如下:

var html = Render.FileToString("footer.html"
               , new { Title = "Foo", page_number = ???, total_pages = ???});

摘自有关page numbering的SelectPdf文档:

// create a new pdf document
PdfDocument doc = new PdfDocument();
doc.Margins = new PdfMargins(10, 10, 0, 0);

// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 24;

// add a new page to the document
PdfPage page = doc.AddPage();

// footer template (100 points in height) with text element
doc.Footer = doc.AddTemplate(doc.Pages[0].ClientRectangle.Width, 100);
PdfTextElement text1 = new PdfTextElement(0, 50, 
    "Page: {page_number} of {total_pages}.", font);
text1.ForeColor = System.Drawing.Color.Blue;
doc.Footer.Add(text1);

// create a new text element and add it to the page
// if page elements are added after header and footer is set, 
// they will not be displayed in those areas.
PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeLongText(), font);
page.Add(text);

我想这是声明:

new PdfTextElement(0, 50, "Page: {page_number} of {total_pages}.", font)

,此模板稍后由SelectPDF引擎填充。如何访问page_number和total_pages?

  • 我使用的模板引擎是Mustache(带有Nustache软件包),但我认为这并不重要。
  • 如果需要的话,我正在使用.net核心。

0 个答案:

没有答案