10

I use many PDF images (converted from SVG) in my LaTeX document (which I create with pdflatex).

I noticed that there are a lot of duplicate embedded subset fonts in my final document. I know this is due to the used images.

After searching around I noticed that merging embedded fonts is a hassle. I do not really understand why, as a tool could combine these subsets, remove all entries with the same encoding and modify the text blocks accordingly (but lets not discuss this further, I'll believe the Internet :) ). I gave up on the embedded subset fonts.

Now I regenerated all images making sure they do not have a subset of the font, but contain the full font. (I checked this with pdffonts.)

After building the document again, it still has the duplicate (non-subset) fonts:

$> pdffonts mydoc.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
...
DejaVuSans                           TrueType          WinAnsi          yes no  yes   1066  0
DejaVuSans-Bold                      TrueType          WinAnsi          yes no  yes   1067  0
DejaVuSans                           TrueType          WinAnsi          yes no  yes   1117  0
DejaVuSans-Oblique                   TrueType          WinAnsi          yes no  yes   1118  0
DejaVuSans                           TrueType          WinAnsi          yes no  yes   1136  0
DejaVuSans-Oblique                   TrueType          WinAnsi          yes no  yes   1137  0
DejaVuSans-Oblique                   TrueType          WinAnsi          yes no  yes   1243  0
...

My question is: why are there duplicate fonts?! It must be very easy for pdflatex to get rid of these duplicate fonts... Or do I need to provide some flag to pdflatex? Or add a package to my document?

Update

The requested document can be downloaded here and is build using:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\includegraphics{image1}
\includegraphics{image2}
\end{document}

If desired, the full project including both test images and the SVG originals can be found here.

The PDF images contain the texts 'Image1' and 'Image2' and both have their font fully embedded. pdffonts shows the following information of the final document:

$ pdffonts mydoc.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
SDXKYB+CMR10                         Type 1            Builtin          yes yes no       6  0
DejaVuSans                           TrueType          WinAnsi          yes no  yes     11  0
DejaVuSans                           TrueType          WinAnsi          yes no  yes     17  0

DejaVuSans is embedded twice, once for each used image. My real document has loads of images, so the problem is more severe...

I do not know whther it is interesting, but pdflatex says:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)

  • 1
    Why do you want to deduplicate the fonts? – Martin Schröder Oct 5 '13 at 21:59
  • I assumed I am doing something wrong, resulting in these duplicate fonts. Furthermore, it seemed a waste of space. – Veger Oct 6 '13 at 9:16
  • Could you make a sample pdf available for analysis online? – Martin Schröder Oct 6 '13 at 12:29
  • I added a minimal example showing the problem – Veger Oct 6 '13 at 21:10
  • 1
    Try adding \pdfinclusioncopyfonts=0 to your preamble somewhere, as suggested in Same font embedded twice when including graphics created with standalone (possible duplicate). – Werner Oct 6 '13 at 21:38
5

The program pdfTeX only merges fonts in the formats Type 1 (or Type 1C). image1.pdf and image2.pdf contains TrueType fonts. From the sources of pdfTeX, pdftoepdf.cc:

static void copyFont(char *tag, Object * fontRef)
{
    ...
    // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
    // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
    ...
}
  • I heard a similar thing in the discussion on the PDFTeX mailing list. I guess I have to convert my fonts somehow! – Veger Oct 14 '13 at 9:13
2

I have made an interesting discovery that could lead to a solution for this issue that will still allow you to use font subsets:

As you already found out, merging font subsets is not something easily achievable (at least not with open source software).

But because you own the raw SVGs, there is an alternative solution: Combine them into a multi-pages PDF. Indeed, if you manage to do so, only one subset will be created: a subset containing the glyphs of all the characters contained in your different SVGs and LaTeX will only embed it once.

Your goal is now to generate a multi-pages PDF properly... I did not manage to find a command line that does it properly, but it surely is doable. The best solution I have found is rsvg-convert but for some reason, it generates a multipages PDF with all the pages of equal size hence breaking your images formats:

rsvg-convert -a -f pdf -o images.pdf *.svg

So let's assume you managed to generate a multi-pages PDF from your SVGs properly, you then simply have to call your images like so:

\includegraphics[page=1]{images.pdf}
\includegraphics[page=2]{images.pdf}

Hope this helps ;)

Update on 18/08/2016:

After a lot of investigation, I did not manage to find any good command to create a multipage PDF from SVGs with page sizes that vary in the generated PDF.

So I finally decided to create my own command inspired by how rsvg-convert works. It is available here: https://github.com/pimpreneil/svgstopdf

This command is very straight forward, here is the syntax:

svgstopdf *.svg out.pdf

Using this command combined with the above LaTeX snippet, you will be able to integrate all your SVGs in a LaTeX document without any font subset duplication!

Update on 19/08/2016:

Because I figured out that this syntax using pages make it hard to figure out which image is being included, I have added an additional --latex-package option to my command in order to generate a LaTeX package that allows for easier integration:

svgstopdf 1.svg 2.svg out.pdf --latex-package

This command will generate an additional svgimages.sty file that brings an includesvg command. Your LaTeX code to load the images will now become:

\usepackage{svgimages}

\includesvg{1.svg}
\includesvg{2.svg}

You may even pass some includegraphics-supported parameters:

\includesvg[scale=0.8]{1.svg}
  • @arnaud-lejsone Works better than rsvg-convert because it properly sizes all the PDF pages to match each SVG size. For any future users, there is also a Windows 32-bit and 64-bit port of this convenient utility: https://github.com/flueterflam/svgstopdf – whatisit Aug 4 '18 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.