How do I reduce PDF file size when merging multiple PDF files?

Q:We are merging multiple PDF files that contain fonts that are fully
embedded. The way we merge files is to take the first file and use it
as a base input, and then we add the rest of the files to that base
input (similar to the code snippet #6 in your PDFPage sample:
http://www.pdftron.com/pdfnet/samplecode.html#PDFPage). We have
noticed that when we do this, all fonts are moved to the output PDF,
even if some of the same fonts are already present. This results in a
larger output PDF.

What we are wondering is if there is a function that we can use to
remove these duplicated fonts, so that only one instance of a single
font is present in the output PDF?

Let me know if you need any more information. Thanks!


A: When merging pages PDFNet does not try to merge fonts or identify
other duplicates (for efficiency reasons). In case you have the same
font appearing in different documents (e.g. when the embedded fonts
are not subsetted), you could replace all font references with a
reference to a single font (after page merging). This would result in
a smaller output PDF document. You could implement this using SDF low-
level API, however as part of the next PDFNet update (v.5.2.1) we will
include a new API Add-on for opimizing PDF files. Besides eliminaing
duplicated resources and a few other optimizations, the new class
( ‘pdftron.PDF.Optimizer’) will include options for recompressing and
downsampling images. In this case you can merge and generate PDF with
optimal file size in a few lines of code. For example, the following v.
5.2 code snippet merges two files and saves the optimized and
linearized PDF.

PDFNet.Initialize();
using (PDFDoc doc = new PDFDoc(/src_path?/)) {
using (PDFDoc from = new PDFDoc(path)) {
from.InitSecurityHandler();
doc.InsertPages(1, from, 1, from.GetPageCount(),
PDFDoc.InsertFlag.e_none);
}
pdftron.PDF.Optimizer.Optimize(doc);
doc.Save(“out.pdf”, SDFDoc.SaveOptions.e_linearized);
}