How do I produce small PDFs when embedding fonts?

Q: We are producing PDF’s using PDFNet SDK, but some files can get
very large because they contain Embedded Fonts. How can we produce PDF
files that are as slim as possible?
A: Using PDFNet you should be able to create PDFs with optimal file
size. If the generated files are large due to fonts you should make
sure that you are not replicating the same font(s) throughout the
document. For example, if you are creating a multi-page document that
contains text in the same font you should create only a single font
instance (using pdftron.PDF.Font.Create...()) and perhaps storing it
is a member variable in your document generation class. Another thing
to consider when creating fonts are last two boolean parameters that
can be passed in Font.Create...() methods. The first flag specifies
whether the font should be embedded or not. The second flag specifies
whether the embedded font should be subsetted or not. For accurate PDF
viewing it is important to embed the font, but you can subset all
fonts in order to decrease the total file size.

Q: I have followed the last suggestion below by setting the two
Boolean parameters, but I am not sure about the result.

What I need to do is have the fonts embedded once at the beginning of
a PDF file ONLY, then Unembedded the rest of the way through the PDF
document to save size.

Can you please clarify if setting these two flags will achieve this,
and what setting I need? If not, is there another way to do this.
A: You need to use Font.Create???() method only once and keep on
reusing the same font object throughout your PDF generation code. For


PDFDoc doc = new PDFDoc();

// Create a font that fill be used throughout the document
Font fnt = Font.Create(doc, Font.StandardType1Font.e_times_roman)

ElementBuilder eb = new ElementBuilder();
ElementWriter writer = new ElementWriter();
Element element;

// Start the first page -----------------
Page page = doc.PageCreate(new Rect(0, 0, 612, 794));

element = eb.CreateTextBegin(fnt, 12);

string data = "Hello World!";
element = eb.CreateTextRun(data);
element.SetTextMatrix(10, 0, 0, 10, 0, 600);
element.GetGState().SetLeading(15); // Set the spacing between lines

writer.WriteElement(eb.CreateTextNewLine()); // New line

// Draw Hello World once again on the next line


// Start the second page -----------------
page = doc.PageCreate();

// Note. we are reusing the font here!
element = eb.CreateTextBegin(fnt, 24);

string data = "Second Page!";
element = eb.CreateTextRun(data);
element.SetTextMatrix(1, 0, 0, 1, 0, 600);


// Save the document, dispose objects.
doc.Save("my.pdf", SDFDoc.SaveOptions.e_linearized);

If your PDF generation method is more complex you could store
ElementBuilder, ElementWriter, Font, and other variables as members of
the PDF generation class. For example:

public class MyPDFGenerator {

private PDFDoc doc = null;
private Font fnt = null;
private ElementBuilder eb = null;
private ElementWriter writer = null;

public void Init() {
  doc = new PDFDoc();
  font = Font.CreateTrueTypeFont(doc, input_path + "font.ttf", true,
  eb = new ElementBuilder();
  writer = new ElementWriter();

void AddPage() {

  element = eb.CreateTextBegin(fnt, 120);

  element = eb.CreateTextRun("Hello World!");
  element.SetTextMatrix(1, 0, 0, 1, 0, 600);



public void Save(string fname) {
   doc.Save(fname, SDFDoc.SaveOptions.e_linearized);


In the above pseudocode the output PDF document will contain only a
single subsetted font. This means that the embedded font will contain
a subset of glyphs used throughout the PDF document and will most
likely be smaller than the input font.