2

so.. The only code I can find that you can use in HiQPdf to number the pages is this:

// add page numbering
Font pageNumberingFont = new Font(new FontFamily("Times New Roman"), 8, GraphicsUnit.Point);
PdfText pageNumberingText = new PdfText(5, footerHeight - 12, 
                                        "Page {CrtPage} of {PageCount}", 
                                        pageNumberingFont);

Any Google search I try pretty much pulls up the same thing.

I'm creating and merging a number of PDF pages together.

The code above makes me think that {CrtPage} and {PageCount} is filled in by some internal variable, but it doesn't.

Contacting their customer service just gets us a photocopy of their demo project that has this same code somewhere in it.

Update:

I forgot to mention that the HiQPdf "merge" example has each page being created separately as a file, then opened back up and put together as one document, but I'm looking at generating the page numbers on the fly.

http://www.hiqpdf.com/demo/MergePdf.aspx

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
KevinDeus
  • 11,988
  • 20
  • 65
  • 97

1 Answers1

3

After spending a couple of hours deciphering their demo project, this is what I've been able to come up with (that works). This is the barest work needed to get page numbers to appear (and since the question was posted a year ago, and likely is about an earlier version, this is how to do it on version 8.1)

var htmlToPdf = new HtmlToPdf();
htmlToPdf.Document.Foot.Enabled = true;

var pageNumberFont = new Font(new FontFamily("Arial"), 5, GraphicsUnit.Point); // 1
var pageNumberText = new PdfText(1, 25, "Page {CrtPage} of {PageCount}", pageNumberFont); // 2
htmlToPdf.Document.Footer.Layout(pageNumberText); // 3

To break down the steps...

1: Font - this is, in my opinion a useful option, but it's a requirement for step 2 as far as I can find, and that sucks. You have to pass a Font object to the PdfText object during instantiation in step 2. I pulled the GraphicsUnit.Point property from their demo and it works, but I can't speak on the other options available for this property and how they perform (if they perform at all).

2: Text - The first two numbers are used for location, the string that follows is what you want displayed. {CrtPage} and {PageCount} will change to the appropriate values on their own. As the last parameter, you pass in the font that you created in step 1.

3: This is where you add the text to the footer to make it appear.

I'm still slogging my way through HiQPdf and learning as I go, so there may very well be better ways of doing this that I have not found yet - but at this point, this looks to be the way to add page count dynamically.

Bardicer
  • 1,405
  • 4
  • 26
  • 43