2011-02-21

Converting PDF to SVG, that doesn't suck

There are a number of converters that take in Adobe Illustrator or Adobe PDF files, and emit SVG files. There are a number of online websites, a few simple little hacky Perl or Python scripts, and expensive commercial proprietary packages from people like Adobe.

They all suck, and emit crap gigantic SVG files.

Here is the way to do it that make perfectly covering SVG files that don't suck.


gs -dBATCH -dSAFER -dNOPAUSE \
-sDEVICE=svg \
-sOutputFile=Logo.svg Logo.pdf


If you have an Adobe Illustrator AI file instead of a PDF file, just put a PDF filename extension on the end, it will work fine.

Howto convert AI to PNG, with good antialiasing & transparency

This does all the transparency handling, antialiasing, and resizing all together inside Ghostscript, so they all work together and make a high quality final image.


mv Logo.ai Logo.ai.pdf
gs -dBATCH -dSAFER -dNOPAUSE \
-dDOINTERPOLATE \
-sDEVICE=png16m \
-dGraphicsAlphaBits=4 \
-r72 \
-SOutputFile=Logo.png Logo.ai.pdf
pngcrush -v \
-rem text \
-l 9 \
-brute \
Logo.png Logo.crush.png
mv Logo.crush.png Logo.png


If you want to shrink the image to half size, change the -r72 to -r36, and so forth.