#1 Re: PDF Engine » Why embed font in the pdf file, the pdf file become vary large? » 2016-04-12 12:50:27

Try this way:

  PDF_Doc.EmbeddedTTF:= True;
  PDF_Doc.EmbeddedTTFIgnore.Text:= MSWINDOWS_DEFAULT_FONTS;
  PDF_Doc.EmbeddedWholeTTF:= false;

Second line avoid "Arial" or "Courier New" to be embeded in the file (but Linux wont see Symbols, for instance!), and third line avoid arab or chinesse characters -if defined in your font- to be embeded in the PDF when the doc is not really using them (a whole TFF font can be 12MB easily, while the used "subset" can be 60KB).

After many tries with this combination, only some special chars in symbol font are failing to show when PDF is open in a linux (greater or equal than, for instance), not sure if the win api for creating subsets fails, so I made some changes to V1.18 so I can give it a list of fonts (with only "Symbol") that, if embeded, must be full embeded.

It saved me for this last problem at a cost of 15KB, but I had to change the source code a little:

1) I cloned all the code related to "SubSetTTFIgnore" and made a clone property named "EmbeddedTTFIgnore".

2) I use this property (bold line on the code) on the part where using subset is decided (procedure TPdfFontTrueType.PrepareForSaving):

        ...
        if ttfSize<>GDI_ERROR then begin
          SetLength(ttf,ttfSize);
          if GetFontData(fDoc.FDC,tableTag,0,pointer(ttf),ttfSize)<>GDI_ERROR then begin
            fFontFile2 := TPdfStream.Create(fDoc);
            if not fDoc.fEmbeddedWholeTTF
              and (fDoc.fSubsetTTFIgnore.IndexOf(fDoc.FTrueTypeFonts[fTrueTypeFontsIndex-1])<0)
              then begin
              if FontSub=INVALID_HANDLE_VALUE then begin
                FontSub := SafeLoadLibrary('FontSub.dll');
                if FontSub<>0 then
                  CreateFontPackage := GetProcAddress(FontSub,'CreateFontPackage');
                  ....

And in my own code, I just do it like this:

uses
  SynPdf, SynCommons;

const
  NO_FONTS: RawUTF8 = 'Arial'#13#10'Courier New'#13#10'Times New Roman';
  SYM_FONT: RawUTF8 = 'Symbol';

  PDF_Doc.EmbeddedTTF:= True;
  PDF_Doc.EmbeddedTTFIgnore.Text:= NO_FONTS;
  PDF_Doc.EmbeddedWholeTTF:= false;
  PDF_Doc.SubsetTTFIgnore.Text:= SYM_FONT;

Board footer

Powered by FluxBB