Search code examples
ghostscript

Ghostscript : how to set the %d Command to a specific value


i use GS with this command line

gswin32c.exe -sDEVICE=tiffg4 -dSAFER -dBATCH -dNOPROMPT -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dNOPAUSE -r600 -g6120x7920  -dPrinted=false -sOutputFile="C:\test\test_%d.tif c:\test\xyz.pdf

That works fine, but it always start with the "1" value, so the output is "test_1.tif".

How do i need to modify the comanndline, to force GS to start with another value, e.g. 7. so GS convert the multipage PDF "xyz.pdf" to singlepage tiff like "test_7.tif, test_8.tif" and so on.

background: i have several pdf and the naming of the pdf is allways different. but i want one ongoing name for the tif file which allways begin with "test" in this case and the incremental value for each pdf page. also my first pdf extract have to be the first tiff files, then the 2nd PDF file extract have to append and so on.

hopefully its a litte bit clear what i need ;)

BR Ralf


Solution

  • The %d convention is simply a C printout format and as mentioned in KenS comment cannot be "offset"

    see https://www.ghostscript.com/doc/current/Use.htm#One_page_per_file

    but there are workarounds mentioned in How to set printf %d offset for Ghostscript?

    However they are perhaps not the most efficient, but may help in some cases, just beware the comments below them.

    The simplest way I will alter the range is to apply a preset such as

    1%d to produce 10 11 12..., or

    2%02d = 201 202 ...

    Again you are limited to the first page will always be ###1 and if you need it to start at ###5 then you need to rename all files post production. That can often be easily scripted depending how well you prepare the desired names.