Sunday 15 July 2012

ghostscript - How do I get output file name containing page X of Y -



ghostscript - How do I get output file name containing page X of Y -

i using ghostscript convert multipage pdf png. need have output filename of png file pagexofy.png x page number , y total number of pages in pdf.

i know can utilize page%d.png current page number.

can help please? have number of multipage pdf manually renaming png files not option.

thank you.

you can't in standard ghostscript. primary reason device has no way know number of pages in input. while can determined single input pdf file, if had 2 input files, how know (while processing file 1) total number of pages in files ?

you might able utilize pdf interpreter reset outputfile device, 1 time number of pages has been determined.

in /ghostpdl/gs/resource/init/pdf_main.ps procedure /runpdfpagerange, routine terminates:

quiet not { (processing pages ) print 1 index =only ( through ) print dup =only (.) = flush } if } ifelse } ifelse } bind def

immediately in front end of "}bind def" seek adding like:

10 lastpage cvs %% (lastpage) dup length 15 add together string %% (lastpage) string dup (page %d of ) exch re-create %% (lastpage) (page %d of ) (page %d of) dup 12 3 index %% (lastpage) (page %d of ) (page %d of) 12 (lastpage) putinterval %% (lastpage) (page %d of lastpage) dup 3 1 roll %% (page %d of lastpage) (page %d of lastpage) (lastpage) length 12 add together %% (page %d of lastpage) (page %d of lastpage) n (.png) putinterval %% (page %d of lastpage.png) << /outputfile 3 1 roll>> setpagedevice

which might work, haven't tried it.

alternatively, utilize ghostscript's pdf_info.ps determine number of pages in input pdf file, invoke ghostscript sec time creating outputfile info returned pdf_info.ps (eg -soutputfile="page %d of 100.png")

update

pdf_info.ps distributed part of ghostscript source, not in prepackaged windows installer need pick re-create of source distribution (www.ghostscript.com, download sources rather windows installer).

the file can found in ghostpdl/gs/toolbin, if open text editor you'll see usage near top in comment. here's illustration of output:

d:\tests>\ghostpdl\gs\debugbin\gswin32c -dnodisplay -sfile=01_001.pdf /ghostpdl/ gs/toolbin/pdf_info.ps gpl ghostscript git prerelease 9.16 (2014-09-22) copyright (c) 2014 artifex software, inc. rights reserved. software comes no warranty: see file public details. 01_001.pdf has 9 pages title: 571l_p author: mwang subject: 571l_p keywords: creator: adobe pagemaker 6.52 producer: acrobat distiller 4.05 windows creationdate: d:20001113140954 moddate: d:20010305115330-08'00' page 1 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 2 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 3 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 4 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 5 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 6 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 7 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 8 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 page 9 mediabox: [0 0 612 792] cropbox: [0 0 612 792] rotate = 0 fonts needed not embedded (system fonts required): arial arial,bold d:\tests>

so need output file , scan it, or pipe output through grep or similar find number of pages.

ghostscript

No comments:

Post a Comment