How would one go about specifying an offset for auto-naming the individual output files? This would probably apply to other programs as well, but I need it to work for Ghostscript right now and can provide my example command for reference.
The following command outputs each individual page of a.pdf as an individual .png file (0.png, 1.png, 2.png, etc…) What I would like to do is start with lets say 23.png, 24.png, 25.png, etc… Is there a way I can pass this via command line? Obviously (%d,23).png doesn’t work, but perhaps there’s another way to do this?
gswin32c -q -dNOPAUSE -sDEVICE=tiffg4 -sOutputFile=%d.png a.pdf -c quit
Thanks!
EDIT:
Looks like -dFirstPage does something similar for offsetting the start page of a multi-page input, but I can’t seem to find anything like this for the output.
FINAL EDIT:
I’ll leave this question open for anyone who may want to pitch in with a better idea, however this is what I ended up doing in Python. (This method could probably be applied to any language that has access to the command line)
Output starts at 23.png and loops until a.pdf EOF
import os
from pyPdf import PdfFileReader
offset = 22
totalpages = PdfFileReader.getNumPages()
start = 1
while start <= totalpages:
os.command('gswin32c -q \
-dNOPAUSE \
-dFirstPage=start \
-dLastPage=start \
-sDEVICE=tiffg4 \
-sOutputFile='+str(start+offset)+'.png \
a.pdf \
-c \
quit')
start = start+1
(BTW, you cannot use
-o %03d.pngto start the output file with000.png— it will start with001.pngas the first page…. Also, your-sDEVICE=tiffg4will output TIFF G4 files, not PNG files, regardless of what suffix you use for the output file….)I can only think about an ugly workaround to achieve what you want. Since Ghostscript can process various input files and commandline sources in the same commandline, but still write the output in one go, you could pre-process a 22-page file file before the one you are interested in:
Now simply delete the first 22 TIFF files, and the first page of your real PDF will be in
023.tiff.An alternative method would be to do it like this:
See the 22
showpagecommands? It causes Ghostscript to process 22 empty pages of PostScript input, before the-f the-real-pdf.pdffile gets its turn. Or even better:In order to create PNG files for the TIFFs, just use
-sDEVICE=pngalpha(orpngmono,png256orpnggray)…