Embedded font to command line PDF export

Post questions on how to use or achieve an effect in Inkscape.
efusien
Posts: 2
Joined: Sun Dec 01, 2013 10:43 am

Embedded font to command line PDF export

Postby efusien » Sun Dec 01, 2013 10:59 am

Hi,
I would like to export a SVG to PDF using the command line.

I want to use embedded SVG fonts, to see beautiful text in the PDF.
As explained in the documentation: "Used fonts are subset and embedded".

Does someone could write a working example of SVG ?
Thanks!

Here is the command line used:

Code: Select all

$ inkscape test.svg --export-pdf test.pdf


I tried to use font-face but it's not working.

Here is the code I used int the SVG file for my tests:

Code: Select all

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<defs>
    <font id="MyFont">

    <font-face font-family="MyFont" />
        <missing-glyph horiz-adv-x="638" />
        <glyph horiz-adv-x="2048" />
        <glyph horiz-adv-x="2048" />
        (...)
        <hkern g1="quoteleft,quotedblleft"    g2="B"    k="130" />
        <hkern g1="quoteleft,quotedblleft"    g2="P"    k="100" />
    </font>
</defs>

    <text x="65" y="50" style="font-family: MyFont; font-size: 16; stroke: none; fill: #000000;">
        <tspan baseline-shift="-1em" x="85" y="72">Here is my text</tspan>
        </tspan>
    </text>

</svg>

Where (...) is the SVG font data. And MyFont is my specific font name.

efusien
Posts: 2
Joined: Sun Dec 01, 2013 10:43 am

Re: Embedded font to command line PDF export

Postby efusien » Mon Dec 02, 2013 3:00 am

I found a workaround to use TTF fonts in my SVG, and export to PDF with command line.
I'm going to explain in 3 steps:


1) I set up new fonts in my Linux environment.
As per the Ubuntu documentation, here are the quick steps:

Copy the .TTF fonts into the /usr/share/fonts folder.
ie: /usr/share/fonts/Sacramento-Regular.ttf

Then, flush the fonts cache:

Code: Select all

sudo fc-cache -f -v


If necessary, check the user rights to access fonts:

Code: Select all

chmod a+r *



2) In the SVG file "test.svg", I just have to use the font-family name. Here "Sacramento".

Code: Select all

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <text x="299" y="50" style="font-family: 'Sacramento'; font-size: 20; stroke: none; fill: rgb(0, 0, 0);">
        <tspan baseline-shift="-1em" x="340" y="75">My text here</tspan>
    </text>
</svg>

Be aware of the font-family name. Check the .TTF file to know the exact name of the font. If the font name contains spaces, you have to add extra quotes into your svg. Like in my example.


3) I use Inkscape command line to export to PDF:

Code: Select all

$ inkscape test.svg --export-pdf test.pdf


"Et voilà". ;)


Return to “Help with using Inkscape”