We are trying to covert a MS Word document template to the PDF format using Aspose Words.
Document doc = new Document(xslData);
ReportingEngine reportingEngine = new ReportingEngine();
reportingEngine.getKnownTypes().add(java.lang.Integer.class);
PdfSaveOptions options = new PdfSaveOptions();
options.setUseCoreFonts(true);
options.setEmbedFullFonts(false);
reportingEngine.buildReport(doc, dataSource, "ROWSET");
doc.save(outPdfStream,options);
It was working correctly before upgrading to JDK 11 . After JDK 11 upgrade its not preserving the font specified inside the template in the generated PDF.
System Specification :-
Before upgrade:-
Java 1.7
Tomcat 8.5
RHEL 6.10
Aspose Words :- 20.6-JDK 17
After upgrade:-
Java 11.0.18
Tomcat 8.5
RHEL 6.10
Aspose Words :- 20.6-JDK 17
How can we get desired font in the Pdf.
@dharanibhoi The problem on your side might occur because the fonts used in your input document are not available on the machine where document is converted to PDF. The fonts are required to render document. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout and appearance differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/
Hi Alexy ,
Thanks for the suggestion .
I was able to find the root cause of the issue and its getting fixed in the Windows machine .
But its not working when deployed to Tomcat in Redhat Linux.
My Guess is that, as the folder is present inside the war files , Its not working. I need to put the font folder outside of war file.
I am an able to set the font through InStream as this opetion is not showing in Aspose words 20.6-JDK 17 .
Could you please suggest any other way.
FontSettings fontSettings = new FontSettings();
String path = this.getClass().getClassLoader().getResource("font").getPath();
String modifedPath = path.substring( 1, path.length() - 1 );
FontSettings.getDefaultInstance().setFontsSources(
new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(modifedPath, true) });
@dharanibhoi Yes, you are right, the fonts folder should be outside the WAR. Unfortunately, Aspose.Words does not read fonts packed into JAR or WAR. So in your case you should either copy the fonts into the OS file system or use StreamFontSource or MemoryFontSource to get fonts from your WAR file and provide them to Aspose.Words.
Hi @alexey.noskov
I think there is bug in StreamFontSource which asks to implement abstract method ‘zzZqO()’ in ‘FontSourceBase’ which can’t be overridden
this kind of bug was present in .net also.
Derive Java Class from StreamFontSource & Implement openFontDataStream() method to Use Stream Font Source.
@dharanibhoi I cannot reproduce the problem on my side. Please try using the latest version of Aspose.Words for Java. The defect reported in the mentioned topic is already fixed.