Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to do the following with ghostscript:

Turn one multipage PDF file (about 3,000 pages, 200mb file) into:

One file per page of the PDF, and convert each (page/file) to EPS or PS (post script(preferably)).

Example:

hello.pdf (10 pages)

would produce:

hello1.ps (page 1 out of 10)
hello2.ps
hello3.ps
...
hello10.ps

How can I do this? I've been trying for 4 days, and can't figure it out.

I have a script I've tried(won't work):

Note: Windows(7) user here.

gs -sDEVICE=epswrite -o documentname-%.eps documentname.pdf

I also don't know how to navigate to the directory where my file resides (cannot figure that out, too). If you can, please show me how.

A big thank you.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

First, I use Linux, not Windows, so I can't test this, but I think something like this is right. (I'm almost tempted to tell you to install Linux inside a virtual machine for this, since stuff like this is sooo much easier with a grown-up operating system, but anyway, here goes my best bet for using Windows.)

First, open a Command/Dos prompt.

To navigate to the folder where your files are, use the CD command followed by the full path to your files in quotation marks. For example, if they are in "C:\Users\Somebody\Documents and Settings\My Documents\PDFs\", then type:

cd "C:\Users\Somebody\Documents and Settings\My Documents\PDFs\"

I think an alternative would be to simply create a batch file inside the same directory as the PDF and run the batch file from there.

OK, now I think you'll have to use the complete path to the Ghostscript executable, which you'll have to find for yourself. I'm going to assume it's "C:\Program Files (x86)\gs\gs9.00\bin\gswin32c.exe" but you'll need to double check that on your own computer. If you're using a different version of ghostscript, or a 32 bit version of Windows 7, it'll be somewhere else. Also make sure you use gswin32c.exe and not gswin32.exe, which is different.

Now find out exactly how many pages are in this PDF. I would know how to do that with a command in Linux, but I have no clue in Windows. I'm going to suppose it's 3002.

Now type in this command at the Command prompt (all one line):

FOR \L %G IN (1,1,3002) DO "C:\Program Files (x86)\gs\gs9.00\bin\gswin32c.exe" -dBATCH -dSAFER -dNOPAUSE -dFirstPage=%G -dLastPage=%G -sDEVICE=pswrite -o hello%G.ps hello.pdf

That's my best guess. But hopefully someone who actually uses Windows can confirm that this works.

For epsfiles instead change -sDEVICE#pswrite to -sDEVICE=epswrite and change hello%G.ps to hello%G.eps.

If you're using a batch file instead, use %%G instead of %G everywhere, change the ='s to #'s.

If "hello.pdf" is changed to something with spaces in it, use quotation marks, "hello world.pdf". Same for "hello%G.ps".


On GNU/Linux (or Mac OS X), the corresponding command would be:

for G in {1..3002} ; do gs -dSAFER -dBATCH -dNOPAUSE -dFirstPage=$G -dLastPage=$G -sDEVICE=pswrite -o "hello$G.ps" "hello.pdf" ; done

to have it autocalculate the number of pages to do, if you have seq and the poppler utilities installed (which come by default on Ubuntu, I believe), you could use:

for G in $(seq 1 $(pdfinfo academicregs.pdf | sed -n 's/Pages:[^0-9]*\([0-9]*\).*/\1/p')) ; do gs -dSAFER -dBATCH -dNOPAUSE -dFirstPage=$G -dLastPage=$G -sDEVICE=pswrite -o "hello$G.ps" "hello.pdf" ; done

Those I've tested and they work.

share|improve this answer
    
Wow, thanks. I'm about to install (dual-boot) Ubuntu 10.04 (or 10.04, or 9.10) to be able to work with such things. I only run Win7 now, because work requires it. Your explanation is quite good, so I will give it a try. If you can, could you also explain it in such a nice way for Ubuntu? Thanks a lot. This command line stuff is kinda gibberish to me. –  godzilla_g Dec 26 '10 at 20:49
    
I'll edit my answer to include instructions for linux. –  frabjous Dec 26 '10 at 20:59
add comment

frabjous' command works, but makes things more complicated than they need to be for a simple task like this.

He runs a separate Ghostscript command for each single page of the PDF once, selecting only the wanted PDF page through the -dFirstPage=... -dLastPage=... parameters. (His Windows version has a little typo as well: it should be for /L %G in... -- instead of for \L %G in...)

This is also unnecessarily slow, because it runs 3002 commands for a 3002 page PDF.

You can achieve the same thing without a 3002-pass loop in one single Ghostscript command pass. On Windows:

 gswin32c.exe ^
   -o hello%04d.eps ^
   -sDEVICE=epswrite ^
    hello.pdf

On Linux or Mac OS X:

 gs \
   -o hello%04d.eps \
   -sDEVICE=epswrite \
    hello.pdf

The %04d part in the output name will create 4digit (page) numbering for the output EPS files, filling non-used digits up with leading zeros (which is not what your desired output example used).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.