Converting PDF to image via Inkscape breaks fonts

I want to convert a PDF page to a PNG image. Following this answer, I tried the following command:

inkscape <PDF PATH> --export-dpi=300 --export-area-drawing --export-background=#ffffff \
    --pdf-page=<PDF PAGE NUMBER> --export-filename="<IMAGE PATH>"

However, any fonts the PDF uses that aren't installed on my system are turned into a default sans serif font in the output image.

Is there a way to make Inkscape use the fonts embedded in the PDF?


Solution 1:

By default, Inkscape tries to match PDF fonts to installed fonts. To fix this, add the option --pdf-poppler, and text will be turned into vector paths before rasterization. The result, then, is that embedded fonts render whether they're installed or not.

That particular command (and indeed, a general command for converting PDF to an image) would be:

inkscape <PDF PATH> --pdf-poppler --export-dpi=300 --export-area-drawing --export-background=#ffffff \
    --pdf-page=<PDF PAGE NUMBER> --export-filename="<IMAGE PATH>"

This corresponds to checking the uppermost radio button in Inkscape's GUI's PDF import dialogue:

Inkscape import settings. “Poppler/Cairo import: Import via external library. Text consists of groups containing cloned glyphs where each glyph is a path. Images are stored internally. Meshes cause entire document to be rendered as a raster image.”