First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

Open .ps plot files using Python

asked Oct 11 '16

Power_System_Engineer gravatar image

Does anyone here know a simple python script to open the .ps files so that it can convert to .pdf? I really hate to have to click on each .ps file so it can convert to .pdf.

Thanks.!

1 answer

Sort by » oldest newest most voted
0

answered Oct 11 '16

perolofl gravatar image

updated Oct 12 '16

One way to do it is to install Ghostscript, which contains program ps2pdf to convert from Postscript to pdf. Then execute the program inside Python with for example:

import os
os.system("ps2pdf diagram.ps diagram.pdf")

All Postscript files in a folder may be processed with the following code:

import os
import glob
for f in glob.glob('*.ps'):
    os.system('ps2pdf '+f+' '+f[0:-3]+'.pdf')
link

Comments

Is Ghostscript free?

Power_System_Engineer gravatar imagePower_System_Engineer (Oct 11 '16)

Yes, it can be downloaded from: http://www.gnu.org/software/ghostscript/

perolofl gravatar imageperolofl (Oct 12 '16)

How would I iterate this code? I have like over 400 stability postscript files in a folder. What I would like to do is tell python to go into that directory and start the conversion for all *.ps files 2 pdf in that directory. Thank you!

Power_System_Engineer gravatar imagePower_System_Engineer (Oct 12 '16)

Thank You!!!

Power_System_Engineer gravatar imagePower_System_Engineer (Oct 12 '16)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: Oct 11 '16

Seen: 4,061 times

Last updated: Oct 12 '16