Hello guys,
I’m using aspose words (aspose-words-16.8.0-jdk16.jar) in my web application, and i have a template word document which holds some merge fields to be set at runtime.
The default font in my template document is Al-Mohanad (arabic font hugely used in saudi arabia).
My process is done in 2-phases: Set the merge fields, then convert to pdf.
At runtime, the 1st phase is done correctly and the resulted word document is displayed successfully in Al-Mohanad, but when trying to convert the resulted word document to pdf, the final pdf is being created in Arial font with small boxes replacing non-break spaces.
How can i get a final pdf document in Al-Mohanad font, knowing that Al-Mohanad font is installed correctly in the windows server and it’s obvious that aspose.words is able to use it in the first phase when filling merge field and generating word document. So my concern is just why did Aspose decide to substitute my font when converting it finally to PDF.
Attached is my initial word template, the result word and the final pdf.
Here below is the backend code:
Document doc = new Document(clsStaticData.getContextPath() + templatePath);
// EVEN I TRIED WITHOUT SETTING DEFAULT FONT AND SETTING FONT FOLDER, BUT GOT THE SAME RESULT.
FontSettings.getDefaultInstance().setDefaultFontName(“al-mohanad”);
FontSettings.getDefaultInstance().setFontsFolder(System.getenv(“windir”)+"\Fonts\", false);
/FontSettings.getDefaultInstance().setFontsFolders(new String[] {}, true);/
/* doc.getMailMerge().setTrimWhitespaces(true); */
doc.getMailMerge().setRemoveEmptyParagraphs(true);
doc.getMailMerge().setRemoveEmptyRegions(true);
// Setup mail merge event handler to do the custom work.
doc.getMailMerge().setFieldMergingCallback(new HandleMergeField());
// This is the data for mail merge.
Object[] keyObjects = fields.keySet().toArray();
String[] fieldNames = Arrays.copyOf(keyObjects, keyObjects.length, String[].class);
Object[] fieldValues = fields.values().toArray();
// Execute the mail merge.
doc.getMailMerge().execute(fieldNames, fieldValues);
TmpFile tmpfile = TmpFile.createNew(“Outgoing Letter”, “.pdf”, true);
OutputStream fout = new FileOutputStream(tmpfile.getFileObject());
// Save the finished document.
doc.setWarningCallback(new HandleDocumentWarnings());
doc.save(fout,SaveFormat.PDF);
fout.flush();
fout.close();