Modify Existing PDF to Add Page N of NNN Footer

How can I use pdftkeither from the command line (or preferably from Ruby) to add page numbers to the bottom of a pre-existing PDF?

I am looking for this format:

  • Page 1 of 2

  • Page 2 of 2

+4
source share
1 answer

If you want to do this using pdftk, you can do this using either an operation multistampor multibackground. But first, you have to prepare a document (with software of your choice) that creates footers Page X of Yon blank pages (in PDF format).

Create Page Footers

LibreOffice, OpenOffice, MS Winword,... , , , , . , PDF-, , .

Ghostscript . ( script, , total). 595842 PostScript ( A4...), Helvetica - 12 pt:

total=100
gs -o 100pagenumbers.pdf    \
   -sDEVICE=pdfwrite        \
   -g5950x8420              \
   -c "/Helvetica findfont  \
       12 scalefont setfont \
       1 1  ${total} {      \
       /PageNo exch def     \
       450 20 moveto        \
       (Page ) show         \
       PageNo 3 string cvs  \
       show                 \
       ( of ${total}) show  \
       showpage             \
       } for"

100- PDF , 100pagenumbers.pdf.

pdftk

pdftk multistamp :

pdftk original.pdf              \
  multistamp 100pagenumbers.pdf \
  output pages-numbered.pdf
+5

Source: https://habr.com/ru/post/1589250/


All Articles