开发者

I want my Ghostscript to output PNG pagenames starting with a higher number, e.g. "31". How?

开发者 https://www.devze.com 2023-01-11 01:31 出处:网络
Using Ghostscript I want to create ~330 PNG files from a PDF (photobook I was given as a gift). Now I want to put these pictures online. I\'m aware of 开发者_如何学Cthe method to use -sOutputFile=some

Using Ghostscript I want to create ~330 PNG files from a PDF (photobook I was given as a gift). Now I want to put these pictures online. I'm aware of 开发者_如何学Cthe method to use -sOutputFile=somename--%03d.png which will give me numbered PNG filenames along the pattern somename--001.png, somename--002.png, etc. However, I want to put ~25-30 more pictures online, and these should have the lower numbered names.

Question: I need to have filenames for the converted PDF output start with "31", i.e. somename--031.png. If I use the Ghostscript numbering method, I do have to manually rename all the PNG files... *shudder*. Is there a way to let Ghostscript's numbering start with "031"? Some hidden parameter to %03d maybe?


I am not aware of any hidden parameter for the %03d notation to make it start its numbering scheme with an offset.

However, here is a trick that can achieve what you want, which takes considerably less effort than manually renaming all your ~330 PNG files.

Run the Ghostscript command like this:

gs \
 -o somename--%03d.png \
 -sDEVICE=png \
 -c "showpage showpage showpage" \
 -f photobook.pdf

Noted the 3 showpage parameters? Effectively, this will insert 3 empty pages into the codestream consumed by Ghostscript. Only after these, it will process your photobook.pdf -- and the file numbering will start with "4". You can now throw away your first 3 .png files, or overwrite them with your additional pictures... :-)

To make it start with "31", you have to insert 30 times the showpage.

Or, to make it easier, you can also create a 30-page PDF helper file consisting of empty pages like this:

gs \
 -o 30-empty.pdf \
 -sDEVICE=pdfwrite \
 -c "1 1 30 { showpage } for"

and then run

gs \
 -o somename--%03d.png \
 -sDEVICE=png \
  30-empty.pdf \
  photobook.pdf
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号