Ask Your Question
0

Open .ps plot files using Python

asked 2016-10-11 12:22:40 -0500

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.!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-10-11 13:22:54 -0500

perolofl gravatar image

updated 2016-10-12 13:37:29 -0500

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')
edit flag offensive delete link more

Comments

Is Ghostscript free?

Power_System_Engineer gravatar imagePower_System_Engineer ( 2016-10-11 16:29:03 -0500 )edit

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

perolofl gravatar imageperolofl ( 2016-10-12 07:53:41 -0500 )edit

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 ( 2016-10-12 11:27:24 -0500 )edit

Thank You!!!

Power_System_Engineer gravatar imagePower_System_Engineer ( 2016-10-12 14:32:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2016-10-11 12:22:40 -0500

Seen: 3,685 times

Last updated: Oct 12 '16