Reducing PDF file size by removing embedded fonts.

Q: When we convert from XPS to PDF there is no option on whether we
want to embedd fonts or have them referenced. We are looking for ways
to reduce PDF file size by replacing embedded fonts with their
reference. Please advise.

A: Removing an embedded font from PDF is an error prone process (both
in terms its effect on visual appearance on the document as well as
potential corruption due to missing encoding etc).

Having said this you can remove all embedded fonts as a post-
processing step after conversion to PDF.
( the files generated from pdftron.PDF.Convert.FromXps() are
normalized and this may work?)

To find all fonts in the document, you can either traverse all page
resources (i.e. 'Font' entry in the page resource dictionary), or
iterate over all document objects. For example:

SDFDoc cos_doc = pdfdoc.GetSDFDoc();
int num_objs = cos_doc.XRefSize();
for (int i=1; i<num_objs; ++i) {
Obj obj = cos_doc.GetObj(i);
if (obj!=null && !obj.IsFree() && obj.IsDict()) {
   DictIterator itr = obj.Find("Type");
   if (itr.HasNext() == false || itr.Value().GetName() != "Font")
   itr = obj.Find("FontDescriptor");
   if (itr.HasNext() == false) continue;
   if (!itr.Value().IsDict()) continue;
   Obj fd = itr.Value();
} }

To shrink the size of resulting PDF you could also run the PDF through
pdftron.PDF.Optimizer (as shown in Optimizer sample - just before
saving the file.