Search code examples
pdffontsghostscriptpostscript

How to use /AlwaysOutline command in ghostscript pdf processing?


I have PDF with different fonts embedded. One of them is color emoji font. For some unknown reason the font with emoji crashes my printing software. The only way I found is to convert all fonts to outlines using gs -dNoOutputFonts parameters. Unfortunately file became very big and quite slow to print.

Then I found that there is AlwaysOutline parameter that should convert to outline only fonts I want.

But the example provided there has no effect for me:

gs -sDEVICE=pdfwrite -o out.pdf -c "<< /AlwaysOutline [/Calibri (Comic Sans) cvn] >> setdistillerparams" -f input.pdf

No matter how I tried, I can't make any particulat font to be outlined.

This is what I tried

For the testing purpose I took pdf with these fonts:

# extracted with pdffonts version 22.02.0
name                                 type              encoding         emb sub uni object    ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
CIGRAP+NotoSans                      CID TrueType      Identity-H       yes yes yes    526  0
PGJSDK+DejaVuSans                    CID TrueType      Identity-H       yes yes yes    534  0
FFCMLR+NotoSansSymbols2              CID TrueType      Identity-H       yes yes yes    538  0
VMLNYD+NotoSans-Italic               CID TrueType      Identity-H       yes yes yes    542  0
ZBMDWE+NotoSans-Bold                 CID TrueType      Identity-H       yes yes yes    546  0

And this is partial output of pdfalyze utility:

...
╭────────────── ─ ─                                                                                            │
│ 526. Font /CIGRAP (Type0)                                                                                │                                                                                            │
╰─────────────── ─ ─
┌─────────────────────────┬──────────────────┐
│                sub_type │ /Type0           │
│               base_font │ /CIGRAP+NotoSans │
│                   flags │ None             │
│            bounding_box │ None             │
│      /Length properties │ None             │
│ total advertised length │ None             │
└─────────────────────────┴──────────────────┘

...

Then I used this command:

gs -sDEVICE=pdfwrite -o out.pdf -c "<< /AlwaysOutline [/CIGRAP+NotoSans] >> setdistillerparams" -f input.pdf

I've tried to use different font names with the suggested command: /CIGRAP+NotoSans, /NotoSans, /CIGRAP, CIGRAP+NotoSans cvn, CIGRAP cvn, (CIGRAP+NotoSans) cvn, ...

Nothing helped. No errors. There are still all same fonts in output PDF.

Does is work for anyone?

What am i doing wrong?


Solution

  • With the help of @KenS I've solved my problem. Let me summarize the results:

    1. Try latest version of ghostscript. In my case it was 9.55 Linux version that did not work properly. Compiling current v10.02.0 (2023-09-13) helped.

    2. Some types of fonts require not just font name to be declared, but both fontname and its CMap (or encoding?) like Identity-H. Like this:

    gs -sDEVICE=pdfwrite -o out.pdf \
       -c "<</AlwaysOutline [/FontName-Identity-H]>> setdistillerparams" \
       -f in.pdf
    
    1. If your software shows font name with prefix like /QXGYNG+CairoFont-0-0, use it without prefix: /CairoFont-0-0.