28/05/2008

Convert PDF to inkscape SVG

I tried to find a vector graphics program on Linux capable of importing pdf, like Corel does on Windows. No luck: Karbon works to a certain extent, Corel on wine seems to be tricky. Scribus can import postscript created by ps2pdf, but might shift lines in the image. There is, however, a workaround to convert PDF to inkscape SVG.
Note: This is once again a historic post, as inkscape has PDF import capabilities since version 0.46 via poppler. It's not in the official SuSE 10.3 repos, but easily available via software.opensuse.org. Works better than the workarounds. On second thought: if you are missing the importing text as curves option, you might want to use this version of pdf2svg (it's also on Ubuntu universe). Works great, even for multi-page documents.

Taken from Calcmaster, who also includes a HowTo for embedded rasterised graphics. You need transfig, ghostscript-library, and pstoedit.
Here's a shell script to speed things up:
#!/bin/sh
if [ ! -f "$1.pdf" ]
then
echo "$1.pdf does not exist in the current directory"
else
pdf2ps $1.pdf $1.ps
pstoedit -f fig $1.ps $1.fig
fig2dev -L svg $1.fig $1.svg
rm $1.fig $1.ps
fi

Save as e.g. pdf2svg, make it executable (chmod a+x pdf2svg), invoke by pdf2svg <filename> without the pdf extension. Copy to /usr/bin to use it systemwide. I then used inkscape to fiddle with fonts, line thicknesses, colours etc. Text characters are imported as vectorised objects and will have to be re-written if you want to change something. Re-exporting to pdf worked OK.

PS: Regarding Corel drawings (*.cdr). Some kind of conversion to SVG can be done with the uniconvertor. Wrought havoc on gradients on one of my trial figures, but imported at least the "bones" of the figure. Usage: uniconv myfig.cdr myfig.svg. Incscape 0.46 is supposed to have an uniconv import filter.

No comments: