I have a PDF document that converts to PNG fine on Windows, but doesn’t work on Linux - it’s very slow, and doesn’t generate any text. I see that there are instructions for adding TrueType fonts for Aspose.Words, is there a similar procedure for Aspose.Pdf? I do have the dejavu font installed…
Would the missing fonts be the cause of the slowdown?
Here’s the stack trace where it always seems to always be stuck:
- java.util.HashMap.createEntry(int, java.lang.Object, java.lang.Object, int) @bci=15, line=897 (Compiled frame)
- java.util.HashMap.addEntry(int, java.lang.Object, java.lang.Object, int) @bci=65, line=884 (Compiled frame)
- java.util.HashMap.put(java.lang.Object, java.lang.Object) @bci=137, line=505 (Compiled frame)
- java.util.jar.Attributes.put(java.lang.Object, java.lang.Object) @bci=12, line=148 (Compiled frame)
- java.util.jar.Attributes.putValue(java.lang.String, java.lang.String) @bci=10, line=168 (Compiled frame)
- java.util.jar.Attributes.read(java.util.jar.Manifest$FastInputStream, byte[]) @bci=301, line=421 (Compiled frame)
- java.util.jar.Manifest.read(java.io.InputStream) @bci=291, line=251 (Compiled frame)
- sun.security.util.SignatureFileVerifier.processImpl(java.util.Hashtable, java.util.List) @bci=20, line=252 (Compiled frame)
- sun.security.util.SignatureFileVerifier.process(java.util.Hashtable, java.util.List) @bci=9, line=239 (Interpreted frame)
- java.util.jar.JarVerifier.processEntry(sun.security.util.ManifestEntryVerifier) @bci=387, line=317 (Interpreted frame)
- java.util.jar.JarVerifier.update(int, byte[], int, int, sun.security.util.ManifestEntryVerifier) @bci=39, line=228 (Compiled frame)
- java.util.jar.JarFile.initializeVerifier() @bci=143, line=348 (Compiled frame)
- java.util.jar.JarFile.getInputStream(java.util.zip.ZipEntry) @bci=25, line=415 (Interpreted frame)
- sun.net.www.protocol.jar.JarURLConnection.getInputStream() @bci=88, line=162 (Interpreted frame)
- java.net.URL.openStream() @bci=4, line=1037 (Interpreted frame)
- org.apache.catalina.loader.WebappClassLoader.findLoadedResource(java.lang.String) @bci=47, line=2689 (Interpreted frame)
- org.apache.catalina.loader.WebappClassLoader.getResourceAsStream(java.lang.String) @bci=47, line=1101 (Interpreted frame)
- com.aspose.pdf.internal.p437.z16.m2(java.lang.String) @bci=14 (Compiled frame)
- com.aspose.pdf.internal.p437.z16.m9() @bci=454 (Interpreted frame)
- com.aspose.pdf.internal.p437.z16.m8() @bci=15 (Interpreted frame)
- com.aspose.pdf.internal.p437.z16.m7() @bci=8 (Interpreted frame)
- com.aspose.pdf.internal.p437.z16.m1() @bci=19 (Interpreted frame)
- com.aspose.pdf.internal.p437.z29.m9() @bci=93 (Interpreted frame)
- com.aspose.pdf.internal.p437.z29.m16() @bci=1 (Interpreted frame)
- com.aspose.pdf.internal.p427.z3.m1(com.aspose.pdf.internal.p413.z4) @bci=11 (Interpreted frame)
- com.aspose.pdf.internal.p416.z40.m2(com.aspose.pdf.internal.p413.z4) @bci=2 (Interpreted frame)
- com.aspose.pdf.internal.p416.z40.m4(com.aspose.pdf.internal.p413.z4) @bci=14 (Interpreted frame)
- com.aspose.pdf.internal.p416.z13.m2(com.aspose.pdf.internal.p413.z4, com.aspose.pdf.internal.p236.z17) @bci=89 (Interpreted frame)
- com.aspose.pdf.internal.p416.z13.m1(com.aspose.pdf.internal.p395.z6, com.aspose.pdf.internal.p399.z11, com.aspose.pdf.internal.p489.z13, com.aspose.pdf.internal.p413.z4[]) @bci=73 (Interpreted frame)
- com.aspose.pdf.devices.z4.m1(com.aspose.pdf.internal.p413.z4[]) @bci=758 (Interpreted frame)
- com.aspose.pdf.devices.z4.m1() @bci=13 (Interpreted frame)
- com.aspose.pdf.devices.ImageDevice.m1(com.aspose.pdf.Page) @bci=56 (Interpreted frame)
- com.aspose.pdf.devices.PngDevice.processInternal(com.aspose.pdf.Page, com.aspose.pdf.internal.p249.z41) @bci=2 (Interpreted frame)
- com.aspose.pdf.devices.PngDevice.process(com.aspose.pdf.Page, java.io.OutputStream) @bci=11 (Interpreted frame)
Hi Tom,
Thanks for your inquiry. Yes, you are right; you need to set the font path on Non-Windows OS (Linux/MAC).
You can use the following methods to get the system folder of fonts or set the font path to font folders. Hopefully, it will help you to fix the issue.
Document.getLocalFontPath() - shows the system folder in which the project will look for fonts.
Document.setLocalFontPath(String) - Setting font path to a custom folder.
Please set the font folder as follows before any operation. Hopefully, it will help you to resolve the issue. If the issue persists, then please share your sample PDF document and environment details, so we will test the scenario and will guide you accordingly.
//adding a new font path
String path = "c:\\fonts\\";
com.aspose.pdf.Document.addLocalFontPath(path);
Moreover, please also check the following code snippet to set the font path if there are more than one font path.
//getting the list for standard font directories in different OS
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
//setting the user list for standard font directories
list.add("c:\\fonts2\\");
list.add("c:\\fonts3\\");
com.aspose.pdf.Document.setLocalFontPaths(list;
//Restoring list for standard font directories by default.
com.aspose.pdf.Document.restoreLocalFontPath();
Please feel free to contact us for any further assistance.
Best Regards,
Thanks for your reply. I have one follow-up question:
If the TrueType fonts are not available on Linux, then Aspose will need to do extra work to make do with what it can find. Is any of this work cached? In other words, will processing speed always be slower for 10 documents that contain TT font “X”, and if so, by about how much?
Hi Tom,
Hi Tom,
Yes, fonts added to LocalFontPaths
are cached, so if you add a font for a document, you do not need to add the same font again for other documents.
Moreover, you can get a list of available fonts using getLocalFontPaths()
. FontRepository.findFont("font name")
verifies whether or not a font exists in the list.
To count the font number:
for (FontSource source : FontRepository.getSources()) {
if (source instanceof SystemFontSource) {
System.out.println("Fonts count: "+((SystemFontSource)source).getFontDefinitions().length);
}
}
Please feel free to contact us for any further assistance.
Best Regards,