'Wkhtmltopdf seems to embed fonts in the PDF in an unpredictable way

I have developed a small engine that produces PDFs using wkhtmltopdf.

While working on my PC (Fedora 24) the generated PDF looked ok. After installing the software on a test server (CentOS 7), I found that the generated PDFs are slightly different.

I'm using a standalone (not installed via package manager) version of the tool. More precisely I'm using version wkhtmltopdf 0.12.3 (with patched qt)

After some investigation I noticed that the PDFs produced on my system contained these fonts:

PDF on Fedora

Instead the PDF generated on the server contains these:

PDF on CentOS

In the CSS I'm using these fonts for the whole document:

/* open-sans-300 - latin */
@font-face {
    font-family: 'Open-Sans-Light';
    font-style: normal;
    font-weight: 300;
    src: url('../fonts/open-sans-v13-latin-300.eot'); /* IE9 Compat Modes */
    src: local('Open Sans Light'), local('OpenSans-Light'),
    url('../fonts/open-sans-v13-latin-300.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-300.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-300.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-300.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-300.svg#OpenSans') format('svg'); /* Legacy iOS */
}

/* open-sans-regular - latin */
@font-face {
    font-family: 'Open-Sans-Regular';
    font-style: normal;
    font-weight: 400;
    src: url('../fonts/open-sans-v13-latin-regular.eot'); /* IE9 Compat Modes */
    src: local('Open Sans'), local('OpenSans'),
    url('../fonts/open-sans-v13-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-regular.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-regular.svg#OpenSans') format('svg'); /* Legacy iOS */
}

/* open-sans-300italic - latin */
@font-face {
    font-family: 'Open-Sans-Light-Italic';
    font-style: italic;
    font-weight: 300;
    src: url('../fonts/open-sans-v13-latin-300italic.eot'); /* IE9 Compat Modes */
    src: local('Open Sans Light Italic'), local('OpenSansLight-Italic'),
    url('../fonts/open-sans-v13-latin-300italic.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-300italic.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-300italic.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-300italic.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-300italic.svg#OpenSans') format('svg'); /* Legacy iOS */
}

/* open-sans-700 - latin */
@font-face {
    font-family: 'Open-Sans-Bold';
    font-style: normal;
    font-weight: 700;
    src: url('../fonts/open-sans-v13-latin-700.eot'); /* IE9 Compat Modes */
    src: local('Open Sans Bold'), local('OpenSans-Bold'),
    url('../fonts/open-sans-v13-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-700.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-700.svg#OpenSans') format('svg'); /* Legacy iOS */
}

So why is wkhtmltopdf embedding extra fonts?

How can I make sure that wkhtmltopdf uses Open Sans only and that I can obtain the same PDF no matter which system I run the software on?

Right now it seems to pick randomly fonts it finds available in the system, besides the ones I specified :|



Solution 1:[1]

On Windows I had the opposite: on the development machine fonts were embedded in the PDF just fine, but on other machines (For example the production server) fonts were missing and not embedded. I investigated the log files and all fonts were properly downloaded from the machine as expected when a PDF was generated. As last resort I installed all fonts on the system of the server (via control panel). This resolved the issue.... I think this has to do with a difference in the fonts installed on the system.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jan