Trying to get font embedding to work

Hi,

I'm trying to get embedding of indirect fonts working with PDFNet.

As a test case I have exported a PDF from OpenOffice with 2 different font choices (attached with the mail). The PDF displays fine in Acrobat reader and Acrobat reports that all three fonts are embedded.

I then strip the fonts using code found in the PDFNet knowledge base:

---snip---

PDFDoc doc = new PDFDoc("test.pdf");
doc.initSecurityHandler();
SDFDoc cos_doc = doc.getSDFDoc();
long 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()) {
         // Process only Fonts
         DictIterator itr = obj.find("Type");
         if ( ! itr.hasNext() || ! "Font".equals(itr.value().getName()) )
              continue;
         log.info("Found font: " + itr.value().getName());
         itr = obj.find("FontDescriptor");
                       if ( ! itr.hasNext() )
               continue;
         if ( ! itr.value().isDict() )
               continue;
         Obj fd = itr.value();
         fd.erase("FontFile");
         fd.erase("FontFile2");
         fd.erase("FontFile3");
   }
}
doc.save("stripped.pdf", 0, null);
doc.close();

---snap---

When I open the resulting PDF file in Acrobat it displays a bunch of boxes instead of the text and also displays a warning that it couldn't find the first of the 2 fonts.

Question: Shouldn't Acrobat find the font installed on my system and use it to render the text?

I then proceed to re-embed the fonts, again with code found in the knowledge base:

--snip---

fontMap.put("BAAAAA+BitstreamVeraSans-Roman", "/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf");
fontMap.put("CAAAAA+BitstreamVeraSerif-Roman", "/usr/share/fonts/truetype/ttf-bitstream-vera/VeraSe.ttf");
     PDFDoc doc = new PDFDoc("stripped.pdf");
doc.initSecurityHandler();
PageIterator pageItr = doc.getPageIterator();
while (pageItr.hasNext()) {
   Page page = (Page) pageItr.next();
   Obj res = page.getResourceDict();
   if (res != null) {
       Obj fonts = res.findObj("Font");
       DictIterator itr = fonts.getDictIterator();
       while (itr.hasNext()) {
           Obj fnt_dict = itr.value();
           Font font = new Font(fnt_dict);
           if (font.isEmbedded()) {
               continue;
           }
           StdFile embedFile = new StdFile(fontMap.get(font.getName()), StdFile.e_read_mode);
           FilterReader myStream = new FilterReader(embedFile);
           Obj fontStream = doc.createIndirectStream(myStream);
           fontStream.putNumber("Length1", embedFile.fileSize());
           font.GetDescriptor().put("FontFile2", fontStream);
           itr.next();
       }
   }
}
doc.save("embedded.pdf", 0, null);
doc.close();

---snap---

This results in a slight change of the boxes and the error message about the missing font disappers. Acrobat Reader says all fonts are embedded, but I still only see boxes where there previously was text.

What am I doing wrong here? I'm trying this on a Ubuntu box.

BTW: The stripped file is marginally bigger than the original test file whereas the reembedded file is almost 10 times larger.

Regards,
Viktor Rosenfeld
--
-------------------------------------------------------
Mathias Peters
iSquare GmbH
Entwicklung
Saarbr�cker Stra�e 36
D-10405 Berlin

Tel.: 030 / 44 35 09-21
Fax.: 030 / 44 35 09-29
Mail: mathias.peters@isquare.de
Web: www.iSquare.de
-------------------------------------------------------
T�V zertifiziert nach ISO 9001:2008
-------------------------------------------------------
isquare GmbH, Berlin
AG Charlottenburg HRB 77436
Gesch�ftsf�hrer: Michael Kapst,
Andreas Koch, Siegfried Ballmann
-------------------------------------------------------
Die Informationen dieser Mitteilung und ihrer Anlage sind vertraulich und nur f�r ihren oben genannten Empf�nger bestimmt. Unbefugtes Weiterleiten, Ver�ffentlichen, Kopieren usw. sind untersagt. Sollte diese E-Mail nicht f�r Sie bestimmt sein, l�schen Sie es bitte umgehend aus Ihrem System und kontaktieren den Absender.

This e-mail and any attachment contains information which is private and confidential and is intended for the addressee only. If you are not an addressee, you are not authorised to read, copy or use the e-mail or any attachment. If you have received this e-mail in error, please notify the sender by return e-mail and then delete it.
-------------------------------------------------------