Avoiding overprinted outlines with pdfrender when converted by Ghostscript

In my document the pdfrender package is used to give some text with a special font a bold outline. Then the resulting file is converted into a PNG (for the website) as well as a PDF with all characters turned into paths (requested by the printing company).

For both conversions I use Ghostscript. The PNG is done with standalone convert feature which calls Ghostscript (or Image Magick which uses Ghostscript internally) and for the font-less PDF I'm using the NoOutputFonts feature.

So far so good, however with pdfrender Ghostscript generates all outlines including the ones which are overlapped by other text parts which should not be visible and aren't in the normal PDF. Is there any Ghostscript setting to avoid this? Alternate solutions which switch from pdfrender to another method or an alternative to Ghostscript are also welcome.

My minimized example code is:

\documentclass[border=1pt,png={ghostscript,gsexe=gswin64c}]{standalone}
\usepackage{xcolor}
\usepackage{LobsterTwo}
\usepackage[T1]{fontenc}
\usepackage{pdfrender}
\begin{document}
\Huge\LobsterTwo\slshape
\textpdfrender{%
TextRenderingMode=2,
LineWidth=.01ex,
StrokeColor=black,
FillColor=yellow,
}{nig}%
\end{document}


The normal PDF looks like this:

The PNG looks like:

And the vectorized PDF (gswin64c -dNoOutputFonts -sDEVICE=pdfwrite -o gstest_vec.pdf gstest.pdf) looks the same:

• Note I used 32c rather than your 64c but it should not make a difference – KJO Feb 9 at 21:25

If I change the sequence of rendering the characters so they are overlaid then I see the following differences

using all 3 characters as one in my TeX viewer I see (same as you do later)

However If I overlay them I see this PNG produced and in my PDF preview

MWE

\documentclass[border=1pt,png={ghostscript,gsexe=gswin32c}]{standalone}
\usepackage{xcolor}
\usepackage{LobsterTwo}
\usepackage[T1]{fontenc}
\usepackage{pdfrender}
\begin{document}
\Huge\LobsterTwo\slshape
\textpdfrender{%
TextRenderingMode=2,
LineWidth=.01ex,
StrokeColor=black,
FillColor=yellow,
}{n}%
\textpdfrender{%
TextRenderingMode=2,
LineWidth=.01ex,
StrokeColor=black,
FillColor=yellow,
}{i}%
\textpdfrender{%
TextRenderingMode=2,
LineWidth=.01ex,
StrokeColor=black,
FillColor=yellow,
}{g}%
\end{document}


Here is the result of running

gswin32c -dNoOutputFonts -sDEVICE=pdfwrite -o gstest_vec.pdf gstest.pdf

Note that with no color definition the screen result looks more like lime

As identified by AlexG many ligatures would probably break although a few may still work

• But this might break ligatures. – AlexG Feb 10 at 20:34

This is not quite what you are after, but maybe you like it even more.

If you only stroke the glyph outlines by means of text rendering mode 5 (5 Tr), which also adds them to the clipping path, and fill an all-embracing rectangle with the desired fill colour afterwards, you get the following:

It is correctly converted to PDF with gs -dNoOutputFonts -sDEVICE=pdfwrite ... (glyph outlines retraced as graphic paths) and also to PNG.

\documentclass[border=1pt,png={ghostscript,gsexe=gswin64c}]{standalone}
\usepackage{xcolor}
\usepackage{LobsterTwo}
\usepackage[T1]{fontenc}

\begin{document}
\Huge\LobsterTwo\slshape
\color{yellow}
\pdfliteral page {0.5 w 0 G 5 Tr}%
nig%
\pdfliteral page {-88888 -88888 99999 99999 re f}

\end{document}