5

How I can get the number of pages before rendering? I need to write the number as words in my document.

Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
Blackbee
  • 51
  • 1
  • 2

1 Answers1

8

For page numbers as numbers:
You don't have to get the number, you can add placeholders (called Fields) to your document and MigraDoc will insert the page numbers automatically while rendering the document.

See AddPageField() in this sample:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

Other field functions are AddNumPagesField(), AddSectionField(), AddSectionPagesField(), AddDateField(), and AddPageRefField(string name)

For page numbers as words:
There is no built-in solution to get page numbers as words.

Where do you need the page numbers? It is possible to have MigraDoc create a document without page numbers and then use PDFsharp to add the page numbers as words in either the header or the footer. If you need page numbers as references within the text then I don't have an easy answer.

See also:
http://forum.pdfsharp.net/viewtopic.php?p=8476#p8476

  • Ok. I have class which rewrite numbers as words. I need to get some int value as number of pages to convert it to words. I realized that I have to render the document in a stream of MigraDoс, received at the same time the number of pages to execute a method svoeg class, and then open the document from a stream in PDFSharp and add a single line? Sorry for English – Blackbee Sep 03 '14 at 08:40
  • After rendering, open the PDF with PDFsharp and PDFsharp will have the page count. The Watermark sample shows how to modify existing pages, the Text Layout sample shows how to draw text. Using MemoryStreams will make this more efficient. Samples page: http://pdfsharp.net/wiki/PDFsharpSamples.ashx – I liked the old Stack Overflow Sep 03 '14 at 09:56