# [pdftex] Merging duplicate embedded fonts

Ross Moore ross.moore at mq.edu.au
Tue Oct 8 21:58:47 CEST 2013

Hello Maarten,

On 07/10/2013, at 19:53, Maarten Bezemer <m.m.bezemer at utwente.nl> wrote:

> Hello,
>
> http://tex.stackexchange.com/questions/136574/merging-duplicate-embedded-fonts
>
> In the end I got suggested to further ask over here.
>
> I have a LaTeX project that contains 2 PDF images. Both have a text with the
> same font that is fully embedded (not subset, to keep things simple).
> The PDF that is created from the LaTeX sources does contain the font twice,
> once for each included image. I suppose that pdflatex should keep only one
> copy, especially since both fonts are fully embedded so it is easy to
> determine they are duplicate.

My understanding is that pdfTeX does not try to parse the internal structure of embedded files, whether they be in PDF or other format. It just assumes that they will work within the context in which you are embedding them, and takes no further responsibility apart from including them straight, within an appropriate PDF XObject wrapper.

How can the software know that the font included within each image is indeed the same?
Even if named similarly, and occupying the same number of bits, this doesn't preclude the internal structure being different. This could well be the case for two different subsets of the same  base font, used in images each having just small amounts of text. But pdfTeX doesn't even look for what fonts are in the image, so no comparison will ever be made.

>
> My LaTeX file is as follows:
>
> \documentclass{article}
> \usepackage{graphicx}
>
> \begin{document}
> \includegraphics{image1}
> \includegraphics{image2}
> \end{document}
>
>
> pdffonts shows:
> \$ 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
>
> In my original document I have lots of images containing texts, resulting in
> lots of duplicate fonts. Obviously, I normally use subsets reducing the size
> of the final document. But I am (also) not able to merge the duplicate
> subsets... So I thought to use fully embedded fonts, but those do also not
> properly merge...
>
> Am I doing something wrong resulting in the duplicate fonts? Or did I
> encounter a bug in pdf(la)tex?

pdfTeX is doing nothing wrong.
If you want to combine the fonts for each image, then those images cannot be considered as independent objects within the PDF. Suppose you want to isolate and extract an image from the final PDF? The reader software will have to be smarter than just extracting a simple XObject. It will need to build a new PDF on the fly, containing all the required fonts, appropriately referenced.  Some PDF readers may be able to do this, but others will not.

Presumably you want a size-reduction in your final PDF. This can only come as a compromise in the functionality according to the browser used by your audience, and/or at the expense of extra processing when the full document is created.

Or try using Acrobat Pro to save a "reduced size" PDF, as an extra step after pdfTeX.
Whether this latter will work may depend upon the characteristics of the font; in particular whether it is known already to the software installation, and it's licensing conditions.

>
> The resulting PDF  file is set online [1],

I'll give APro a try and get back to you with the results.

> as well all the source files [2]
>
> Best regards,
>  Maarten
>
>
> [1]: https://dl.dropboxusercontent.com/u/9671810/mydoc.pdf
> [2]: https://dl.dropboxusercontent.com/u/9671810/mydoc.zip

Cheers,

Ross
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8613019585609436, "perplexity": 3423.4401259374126}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2023-14/segments/1679296945289.9/warc/CC-MAIN-20230324211121-20230325001121-00222.warc.gz"}