How to convert PostScript script to a .ps file for viewing in PDF viewer or to PNG

Reading about Gerard Huet’s paper on the geometry of the Shri Yantra available in PDF format at this link http://pauillac.inria.fr/~huet/SKT/sanskrit.html.orig, I was prompted to try out the Postscript code he had in and Appendix in the paper.

After typing the code into a .txt file, the file did not render using Evince or a PDF reader on Linux Mint or Ubuntu.

To make it render, open a terminal window and enter:
$ ps2ps mypsfile.ps mm.ps <enter>

where mypsfile.ps is the source of the Postscript instructions to be rendered and mm.ps is the output file that can be read with any PDF reader. Note that the command will also display errors in the PostScript code too, if any.

In order to convert mypsfile.ps to PNG format, Install imagemagick as follows:
$ sudo apt-get install imagemagick-6.q16hdri <enter>

To convert the file, enter:
$ convert mypsfile.ps mm.png <enter>
where mm.png is the output transparent png file. To convert to jpg, type mm.jpg as the output file.

Note that the convert command will not work directly for the above purpose. It displays the error:
attempt to perform an operation not allowed by the security policy `PDF’ @ error/constitute.c/IsCoderAuthorized/408.

To fix the above error, edit the policy.xml file as below in vi or any other editor:
$ sudo vi /etc/ImageMagick-6/policy.xml <enter>

At the end of the file, you will find:

<!-- disable ghostscript format types -->
  <policy domain="coder" rights="none" pattern="PS" />
  <policy domain="coder" rights="none" pattern="PS2" />
  <policy domain="coder" rights="none" pattern="PS3" />
  <policy domain="coder" rights="none" pattern="EPS" />
  <policy domain="coder" rights="none" pattern="PDF" />
  <policy domain="coder" rights="none" pattern="XPS" />

In the line that says

<policy domain="coder" rights="none" pattern="PS" />

Change the rights=”none” to rights=”read | write

Save the file and now use the convert command.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s