0

I'm using the following wrapper WkHtmlToXSharp to convert HTML reports into PDF. I would like to also record the page count after the conversion is complete.

Is there a way to extract the page count from the binary PDF in memory? Or do I need to use secondary PDF libraries such as iTextSharp to extract the page count from the PDF?

Using the Javascript in the page footer/header is not acceptable solution as this can be a data heavy 60-80 pages report.

Thanks, Rafi

rghazarian
  • 260
  • 2
  • 9

1 Answers1

0

If you generate the PDF yourself, you could try counting them directly from the PDF source format. There are tutorials available for that in for example in http://www.codeproject.com/Articles/14768/Counting-PDF-Pages-using-Regular-Expressions

I won't repeat them here but the idea is to count how many /Type /Page hits there are on the PDF using regex. Open a generated PDF in a good text editor and you'll see them yourself. Watch out for one "/Type /Pages" which throws the number off by one, finding a good regex is easy when you "control" the PDF generation or at least know that it's consistent.

Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100