PDA

View Full Version : Convert hundreds of PostScript files to pdf




ign
Oct 21, 2009, 03:15 AM
Hello,

I need to convert a bunch of PostScript files to pdf.
With OSX one can open the postscript file and save it in pdf,
but I can't do it one by one, it'd take for ever.
Is there a command in terminal that does it for a batch of files ??

thank you!



mysterytramp
Oct 21, 2009, 05:39 AM
You might want to look at ImageMagick (http://www.macupdate.com/info.php/id/12447/imagemagick)

With that, you could write a shell script to convert each file.

mt

rossipoo
Oct 21, 2009, 05:40 AM
Have you tried Automator?

dazey
Oct 21, 2009, 07:56 AM
Automater would be the first thing I would try as well.

costabunny
Oct 21, 2009, 08:03 AM
Ive used CS3 batch for BMP to Tiff - I don't know but I'd take a guess that it will do postscript to PDF also ? (maybe someone knows)

whooleytoo
Oct 21, 2009, 10:09 AM
In /Library/Scripts/Printing Scripts/ you'll find the Convert to PDF applescript, you should be able to modify that to do what you want. It ultimately uses cupsfilter, so if you want to write a shell script rather than Applescript you could look at the man documentation for that.

lloyddean
Oct 21, 2009, 10:51 AM
Is there something wrong with using the Terminal and systems supplied 'pstopdf' tool?

mperkins37
Oct 21, 2009, 02:45 PM
Drop em all on acrobat distiller.

balamw
Oct 21, 2009, 03:17 PM
Is there a command in terminal that does it for a batch of files ??


Is there something wrong with using the Terminal and systems supplied 'pstopdf' tool?

+1

B

jaw04005
Oct 21, 2009, 03:19 PM
I thought PostScript was a printer language, not a file type like PDF. Oh well, you learn something everyday.

lloyddean
Oct 21, 2009, 05:24 PM
No answer from anyone knowledgeable in shell scripting, that includes me, but I'll try anyway.

Save the following to a file called 'ps2pdf' somewhere in your path followed by a 'sudo chmod 777 ps2pdf' on the file to give it permission for anyone to read, write and execute it.

Invoke it with the list of files you wish to convert. PDF files will be created with the same name as the source files minus the .ps but appended with .pdf.
Example

ps2pdf *.ps


#!/bin/bash
#
# sudo chmod 777 ps2pdf

for f in *.ps
do
pstopdf "$f"
done

chown33
Oct 21, 2009, 07:44 PM
for f in *.ps


That line should be:

for f in "$@"


You don't have to make it a separate shell script, though. The OP could just copy and paste these lines into a Terminal window (assuming his shell is bash).

for f in *.ps
do
pstopdf "$f"
done


This assumes the ps files all end in ".ps", and they are all in the current directory. To improve the script, though, we'd need the OP to tell us more about where the ps files are located, e.g. whether they're in nested sub-dirs, on a remote server, etc.

lloyddean
Oct 21, 2009, 07:58 PM
That line should be:

for f in "$@"


You don't have to make it a separate shell script, though. The OP could just copy and paste these lines into a Terminal window (assuming his shell is bash).

for f in *.ps
do
pstopdf "$f"
done


This assumes the ps files all end in ".ps", and they are all in the current directory. To improve the script, though, we'd need the OP to tell us more about where the ps files are located, e.g. whether they're in nested sub-dirs, on a remote server, etc.


Thanks for that. Its been a verrry long time since I've messed around with shell scripting.

Assumptions were all there was to go on - but I believe it may be best to provide a scripted method that hangs around versus one that has to be remembered and retyped if this becomes a frequent event.

balamw
Oct 21, 2009, 10:48 PM
This assumes the ps files all end in ".ps", and they are all in the current directory. To improve the script, though, we'd need the OP to tell us more about where the ps files are located, e.g. whether they're in nested sub-dirs, on a remote server, etc.

You could also just get rid of the for loop and replace with find and xargs if things are more complicated. (e.g. you need to recurse a directory tree)

Read here for some examples http://en.wikipedia.org/wiki/Xargs or just "man xargs"

B

ign
Oct 22, 2009, 02:32 AM
thanks a lot for all the suggestions. I had tried with automator and it actually worked even though the resulting pdf had 5x the size of the pdf created doing it one by one in finder.

Anyway I'll go for the terminal command which seems the most robust and fast solution. I'll play with it and see if I make it, I'll let you know !

cheers

gorn
Oct 22, 2009, 04:16 PM
find . -name \*.ps -exec pstopdf {} \;


that will find them in subdirectories too.

goodrunb
Oct 25, 2009, 06:21 PM
http://www.goodrunb.com/irenamer/