-2

I'm trying to add page numbers to all pdfs in a folder through bat script.
I am unable to install any software, and hence I can only use what's on my windows machine.

I do have ghostscript, and some pdf readers (also Nuance which has the gr8 Pdf creator assistance which can do this in a jiffy - however, not from batch).

I've found this answer here: How can I add a footer to the bottom of each page of a postscript or pdf file in linux? But to no success!

And I've saved the "code" to a .ps file. after that i run:

for /f %%a in ('dir /b *.pdf') do (
gswin64c -q -dQUIET -dBATCH-dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=c:\folder\%%a -f AddPn2Pdf.ps )
Community
  • 1
  • 1
TrueTom
  • 31
  • 10
  • 1
    no success? what is the problem? in your code snippet the closing parenthesis is missing BTW. – Jean-François Fabre Nov 23 '16 at 19:43
  • You seem to specify an output file, but I do not see where you are specifying the input file which in theory should be your FOR variable. You are only using the FOR variable for the output file. – Squashman Nov 23 '16 at 20:04
  • The code you are trying to use is a BATCH-FILE. Saving it as a .PS file, I guess could be PowerShell but I thought they used .PS1 for the extension. This code will not run under powershell. – Squashman Nov 23 '16 at 20:05
  • If you have java, you can use [Apache FOP](http://xmlgraphics.apache.org/fop) and [Apache Pdfbox](http://pdfbox.apache.org) - the first to generate a pdf file iwith consecutive page numbers (only) at the bottom and the latter to overlay as many pages as you need over each of the pdfs. No install except Java runtiime. – Stefan Hegny Nov 23 '16 at 20:12
  • deleted comment,. gone to an answer. – KenS Nov 23 '16 at 20:31

1 Answers1

0

The post you point to will work just fine for PostScript input, which is what its intended for. It won't work at all for PDF input, because PDF is not PostScript.

It is possible to do what you want by writing PostScript, but its non-trivial, you would have to learn quite a bit of PostScript to get it to work and it would never be reliable.

The best solution whenever you want to modify a PDF file is to go back to the original document, modify it and remake the PDF.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • So. If I first convert every PDF in the folder to postscript, I can do the same script, but for the PS file? Modifying the original in adobe pro is not an option :(. I've successfully added the filename to each header, using pdfstamper (which i believe runs with iText somehow). – TrueTom Nov 23 '16 at 21:12
  • Possibly it will work, but the expense of converting to PostScript is considerable. Pages with transparency will turn into images, annotations will become rendered as part of the page, metadata will be irretrievably lost, search will probably cease working, there may be other problems as well. – KenS Nov 24 '16 at 08:04