Convert hundreds of PostScript files to pdf

Discussion in 'Mac Programming' started by ign, Oct 21, 2009.

  1. ign
    macrumors member

    Joined:
    Mar 16, 2004
    Location:
    Firenze
    #1
    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!
     
  2. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #2
    You might want to look at ImageMagick

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

    mt
     
  3. macrumors regular

    Joined:
    Jun 7, 2009
    #3
    Have you tried Automator?
     
  4. macrumors 6502

    Joined:
    Dec 9, 2005
    #4
    Automater would be the first thing I would try as well.
     
  5. macrumors demi-goddess

    costabunny

    Joined:
    May 15, 2008
    Location:
    ~/
    #5
    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)
     
  6. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #6
    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.
     
  7. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #7
    Is there something wrong with using the Terminal and systems supplied 'pstopdf' tool?
     
  8. macrumors 6502a

    mperkins37

    Joined:
    Jan 17, 2007
    Location:
    Phoenix, AZ
    #8
    Drop em all on acrobat distiller.
     
  9. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #9
    +1

    B
     
  10. macrumors 601

    jaw04005

    Joined:
    Aug 19, 2003
    Location:
    AR
    #10
    I thought PostScript was a printer language, not a file type like PDF. Oh well, you learn something everyday.
     
  11. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #11
    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

    Code:
    #!/bin/bash
    #
    # sudo chmod 777 ps2pdf
    
    for f in *.ps
    do
    	pstopdf "$f"
    done
    
     
  12. macrumors 603

    Joined:
    Aug 9, 2009
    #12
    That line should be:

    Code:
    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).

    Code:
    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.
     
  13. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #13

    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.
     
  14. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #14
    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
     
  15. ign
    thread starter macrumors member

    Joined:
    Mar 16, 2004
    Location:
    Firenze
    #15
    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
     
  16. macrumors member

    Joined:
    Jun 17, 2009
    #16
    Code:
    find . -name \*.ps -exec pstopdf {} \;
    
    that will find them in subdirectories too.
     
  17. macrumors newbie

    Joined:
    Apr 13, 2009
    #17

Share This Page