Open .ps plot files using Python
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.!
First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
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.!
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')
Yes, it can be downloaded from: http://www.gnu.org/software/ghostscript/
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!
Asked: 2016-10-11 12:22:40 -0500
Seen: 3,844 times
Last updated: Oct 12 '16