render text as vector instead of embedding fonts with ghostscript

i recently had the problem that a pdf i generated from troff didn't render correctly for someone else. instead of characters, unicode replacement boxes were displayed. it rendered fine on linux, windows and android with different viewers. it later turned out that the problem likely is a bad javascript pdf viewer which isn't able to properly render embedded font (subsets).

despite this being a rather special problem, i looked into how to create pdfs that are not relying on fonts.

the internet came up with solutions which are not great, most involved using graphicsmagick to render the pdf and save it as pdf, essentially converting everything to a bitmap picture. this might be good if one directly sends it to a printer. for sending it to people this isn't a great option, the files are really big and only look good at a certain zoom level.

ghostscript does have an option to convert text to paths, as described in the ghostscript manual:

-dNoOutputFonts

Ordinarily the pdfwrite device family goes to considerable lengths to preserve fonts from the input as fonts in the output. However in some highly specific cases it can be useful to have the text emitted as linework/bitmaps instead. Setting this switch will prevent these devices from emitting any fonts, all text will be stored as vectors (or bitmaps in the case of bitmapped fonts) in the page content stream. Note that this will produce larger output which will process more slowly, render differently and particularly at lower resolution produce less consistent text rendering. Use with caution.

just use -dNoOutputFonts when calling ghostscript or a wrapper like ps2pdf, and the resulting file will not contain any fonts.

this indeed works very nice. the resulting pdf is bigger than with embedded fonts but not nearly as big as with the bitmaps and should be rendered correctly everywhere (knock on wood). a drawback is that the text is a vector image so it isn't selectable. having the real text data below this vector image, like for OCRed pdfs would be ideal. i don't know how to move ghostscript to do this yet though :)