pdfpodofo

How to embed Base14 fonts using the PoDoFo library


I am using PoDoFo library to generate a PDF document. All fonts except Base14 ones ("Courier", "Helvetica", "Times", "Symbol", "ZapfDingbats") are embedded. How to embed these 4 Base14 fonts?


Solution

  • By default the CreateFont() function uses the EFontCreationFlags::eFontCreationFlags_AutoSelectBase14 attribute (so it doesn't have to be given).

    PoDoFo::PdfDocument *pDocument;
    ... 
    pDocument->CreateFont("Times", false, false, false, 
        PoDoFo::PdfEncodingFactory::GlobalIdentityEncodingInstance(),
        PoDoFo::PdfFontCache::eFontCreationFlags_AutoSelectBase14
    );
    

    This attribute makes the function automatically check if the font is a Base14 one, and if it is, then PoDoFo doesn't embed the font. Use the PdfFontCache::eFontCreationFlags_None flag to embed the font.

    PoDoFo::PdfDocument *pDocument;
    ... 
    pDocument->CreateFont("Times", false, false, false,
        PoDoFo::PdfEncodingFactory::GlobalIdentityEncodingInstance(),
        PoDoFo::PdfFontCache::eFontCreationFlags_None
    );