Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I number pages in a PDF with PhantomJS?

I'm using PhantomJS to generate PDFs from HTML. I want to have a page footer that says "page 1 of 5", "page 2 of 5", etc. Is there any way to do that with PhantomJS?

(I know about CSS3 page-based counters, but as far as I can tell PhantomJS doesn't support them.)

like image 306
cjm Avatar asked Nov 05 '13 20:11

cjm


1 Answers

Yes, it's possible.

Look at the printheaderfooter.js example on GitHub.

Basically, two callbacks are invoked when printing : one for header and another for footer. It's not in the doc, but the example is easy to understand.

The only problem you may have with this feature is if you want to apply custom styling or include images. Sometimes, it's a bit tricky...

like image 184
Cybermaxs Avatar answered Nov 04 '22 09:11

Cybermaxs