Roland's homepage

My random knot in the Web

Converting PostScript and PDF images to SVG format

As a long-time UNIX user I’m used to programs generating PostScript output, and I’m fluent enough in that language to produce graphics in it myself. Unfortunately PostScript is hard to display e.g. on the Web. Luckily another vector format, svg has arisen that is supported by modern browsers.

To convert PostScript images into svg while keeping the figures’ bounds intact, I use the following programs;

pstopdf
A Ruby script from the TeXLive distribution. Converts the PostScript picture to pdf format while keeping the bounding box intact. Note that this is not one of the commercial programs that go by the same name.
pdf2svg
To do the actual conversion to svg format.

Note that the ps2pdf converter that comes with Ghostscript doesn’t work well in this case as it renders the PostScript file as a full page. For including svg pictures in webpages it is better to use the <embed> tag than to use the <img> tag, at least in Mozilla Firefox. Only the embed tag actually renders the picture.

It is assumed that the PostScript file has a correct BoundingBox set. If not, the proper DSC comment for a file foo.ps can be generated with the command

gs -q -sDEVICE=bbox foo.ps -c quit

The resulting BoundingBox line should be added or replaced on the second line of foo.ps. The workflow to convert it to svg is;

pstopdf foo.ps
pdf2svg foo.pdf foo.svg
rm -f foo.pdf

For comments, please send me an e-mail.


Related articles


←  Managing configuration files Backups  →