Aspose Words Version: aspose-words.20.3 (Java JDK)
Environment: macOS Catalina 10.15.3
Development Environment: IntelliJ IDEA 2019.3
Microsoft Word for Mac: Version 16.35
Using the following MERGEFIELD tags:
«IMB»
«MailRecipient»
«Address1»
«City», «State» «ZipCode»
The “IMB” field value is “TFTADDFDDDFTDAFTTTFTFFAFDDFDFFFFFFTTDATFAFDFDFAFFDAFAFFFTDAFTFDAA” with the USPSIMBStandard font specified in the Word document.
The other values are using “Proxima Nova” True Type font.
The output PDF embeds the “Proxima Nova” and “USPSIMBStandard” fonts however, the <> tag is using “Arial Unicode MS” font when inspecting the PDF using Acrobat Pro DC (Properties->Fonts).
Within the Word document (docx) I placed the encoded IMB string as static text and specified the USPSIMBStandard font from the pull-down fonts and it renders correctly. The dynamic string for the field “IMB” does not.
Console Output:
strKey:[ZipCode][96813-2900]
strKey:[State][HI]
strKey:[FirstName][Ronon]
strKey:[LastName][Dex]
strKey:[IMB][TFTADDFDDDFTDAFTTTFTFFAFDDFDFFFFFFTTDATFAFDFDFAFFDAFAFFFTDAFTFDAA]
strKey:[City][HONOLULU]
strKey:[Address1][364 S KING STREET]
strKey:[MailRecipient][RONON DEX]
Reviewing the available cases similar I’ve added the following code:
File fCustomFonts = new File( “CustomerFonts/” );
if ( fCustomFonts.exists() ) {
ArrayList fontSources = new ArrayList(Arrays.asList(FontSettings.getDefaultInstance().getFontsSources()));
System.out.println( “CUSTOMER FONTS:[” + fCustomFonts.getAbsolutePath() + “]” );
FolderFontSource folderFontSource = new FolderFontSource( fCustomFonts.getAbsolutePath(), true );
fontSources.add( folderFontSource );
FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.toArray( new FontSourceBase[ fontSources.size() ] );
FontSettings.getDefaultInstance().setFontsSources( updatedFontSources );
fontSetting.setFontsSources( updatedFontSources );
}
Hashtable dataMap = getMergeData();
LoadOptions loadOptions = new LoadOptions();
loadOptions.setFontSettings( fontSetting );
Document doc = new Document( strWordDoc, loadOptions );
// Execute mail merge.
doc.getMailMerge().execute( mergeKeys, dataMap.values().toArray() );
HandleDocumentWarnings callback = new HandleDocumentWarnings();
doc.setWarningCallback( callback );
doc.save( strOutput, pdfOptions );
The callback method returns:
Font substitution: Font ‘Cambria’ has not been found. Using ‘Arial Unicode MS’ font instead. Reason: font info substitution.
Any suggestions would be greatly appreciated.
Bill Sanders