PDF output from KiCad in Linux from SVG

kicad-appicon-128

The ps2pdf-d script I developed earlier worked fine for getting PDF from KiCad‘s Eeschema using Postscript as an intermediate format, but it falls short with Pcbnew because there is no way in Pcbnew to make a Postscript file that merges layers. Using File > Plot, you can pretty easily get Postscript files of individual layers, but you can’t get a merge of, say, the top copper, top silkscreen, and drawing layers.

But you can do this with File > Print SVG. You’ll need to play around with the dialog to get the SVG you want, but it’s pretty simple. Thus, svg2pdf-d was born:

#!/bin/bash

# DESTRUCTIVELY convert all svg files in working directory to pdf.
# Source file extension is case sensitive!

# Requires inkscape.
# Mithat Konar 2013 <http://mithatkonar.com>

OPTIONS=""

FILES=$(ls -1 *.svg)

# There are two alternatives below for doing the conversion.

#~ ## BEGIN ALT_1:
#~ ##     This approach isn't optimal because it restarts inkscape per
#~ ##     file. However the simplicity lends itself to porting (e.g., to
#~ ##     windows BAT.
#~ for file in $FILES
#~ do
    #~ base=$(basename $file .svg)
    #~ inkscape --without-gui ${OPTIONS} ${file} --export-pdf=${base}.pdf
#~ done
#~ ## END ALT_1

## BEGIN ALT_2:
##     This approach seems to be better because it starts one inkscape
##     instance for all files, but it also involves a temp file.
# Make a temp file to store batch commands.
CMDFILE=$(mktemp) || { echo "Failed to create temp file"; exit 1; }

# build up the list of commands
for file in $FILES
do
    base=$(basename $file .svg)
    echo "${file} --export-pdf=${base}.pdf" >> $CMDFILE
done

# Process commands in a batch.
DISPLAY= inkscape ${OPTIONS} --shell < $CMDFILE rm -f $CMDFILE echo ## END ALT_2 # Delete old files. # Since inkscape exits with 0 even with errors, we need to explicitly check # for conversion before deleting originals. rv=0 for file in $FILES do     base=$(basename $file .svg)     if [[ -f ${base}.pdf ]]; then         rm $file     else         echo "$file not converted." 1>&2
        rv=1
    fi
done
exit $rv

svg2pdf-d requires Inkscape, which is not really that light. But it’s arguably something that should be in your FOSS toolkit anyway.

The Inkscape conversion used in svg2pdf-d seems to work fine with the SVG files generated by Eeschema as well. I’m seeing only minor differences between the SVG→PDF versus PS→PDF conversions, and the SVG→PDF files appear to have truer color. So the SVG approach may be the better one in general.

I’ll add I have added this to the wiki after a bit more testing making significant revisions.

6 thoughts on “PDF output from KiCad in Linux from SVG”

  1. Thank you, thank you, thank you!!!!

    I was tearing my hair out trying to get any kind of usable printer output from pcbnew. Everything was coming out very grainy and pixelated. The tracks looked like they were laid down with the old tape method and there were ugly wedge-shaped gaps where the tracks made a 45 deg. turn.

    Your script saved the day.

    Thanks again.

Leave a Reply to Miguel Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.