We’re inserting a doc/docx (arial_embedfont.docx),which includes Arial font subset-embeded(*) inside, into a main document (mytemp.rtf). PDF generated with mainDoc.save(SaveFormat.PDF) does use Arial font from the arial_embedfont.docx. (1.pdf)
However when this maindocument is converted to byte array, and then save this copied byte array document as PDF format, the Arial font from arial_embed.docx is not available, resulting in strings showing up as unexpected fonts.
Is this expected? How can we use the Arial subset fonts available with the copied byte array document?
Code is like this:
mainDoc = new Document(dataDir + "mytemp.rtf");
DocumentBuilder builder = new DocumentBuilder(mainDoc);
builder.moveToDocumentEnd();
Document docToInsert = new Document(dataDir + "arial_embedfont.docx");
builder.insertDocument(docToInsert, ImportFormatMode.USE_DESTINATION_STYLES);
mainDoc.save(outDir + "1.pdf", SaveFormat.PDF);
ByteArrayOutputStream out = new ByteArrayOutputStream();
mainDoc.save(out, SaveFormat.DOCX);
mainDoc.save(dataDir +"maindocSaved.docx",SaveFormat.DOCX);
byte[] aa = out.toByteArray();
Document docAA = new Document(new ByteArrayInputStream(aa));
docAA.setFontSettings(fontSettings);
docAA.save(outDir + "2.pdf", SaveFormat.PDF);
1.pdf has Arial font embed.
2.pdf is not.
I noticed maindocSaved.docx does not have fonts embed inside anymore either.
(*1)
arial_embedfont.doc or .docx was saved with
Word option > Save > Embed fonts in the file checked and "“Embed only the characters used in the document”