Below is my code. The code was run on a Linux server and it is impossible for me to install the fonts on the system. I have tried many methods mentioned in different topics including FontRepository.setLocalFontPaths, FontRepository.getSources()
.add(new FolderFontSource(FONT_DIR)), and FontRepository.addSystemFont(font) but still got Cannot find any fonts installed on the system
. I thought FontRepository.addSystemFont will have already added the fonts to the system path???
// ------------------------
// Before adding system font:
// Font arial = FontRepository.findFont("Arial"); // Raises "Font Arial was not found."
com.aspose.pdf.FontRepository.setLocalFontPaths(ImmutableList.of(FONT_DIR));
FontRepository.getSources().add(new FolderFontSource(FONT_DIR));
// msttcorefonts
List<String> fontFiles =
ImmutableList.of("/arial.ttf", "/cour.ttf", "/georgia.ttf", "/times.ttf", "/verdana.ttf");
for (String fontFile : fontFiles) {
// Add system font.
String fontDir = FONT_DIR + fontFile;
InputStream fontStream = new FileInputStream(fontDir);
Font font = FontRepository.openFont(fontStream, FontTypes.TTF);
FontRepository.addSystemFont(font);
}
// ------------------------
// After adding system font:
Font arial = FontRepository.findFont("Arial");
System.out.println("Font name: " + arial.getFontName()); // Arial
System.out.println("IsEmbedded: " + arial.isEmbedded()); // true
System.out.println("IsAccessible: " + arial.isAccessible()); // true
System.out.println("IsSubset: " + arial.isSubset()); // true
System.out.println(com.aspose.pdf.FontRepository.getLocalFontPaths());
com.aspose.pdf.Document document = new com.aspose.pdf.Document(input.newInput());
ByteString.Output outputStream = ByteString.newOutput();
document.save(outputStream, com.aspose.pdf.SaveFormat.DocX);
return outputStream.toByteString();
Below is the error trace:
class com.aspose.pdf.internal.ms.System.l6n: Cannot find any fonts installed on the system.
com.aspose.pdf.internal.l25l.lv.lI(Unknown Source)
com.aspose.pdf.internal.l25l.lv.lI(Unknown Source)
com.aspose.pdf.internal.l25l.lv.lI(Unknown Source)
com.aspose.pdf.internal.l99t.lc.lI(Unknown Source)
com.aspose.pdf.internal.l99t.l0t.lI(Unknown Source)
com.aspose.pdf.internal.l0j.l0l.lI(Unknown Source)
com.aspose.pdf.internal.l0j.l0l.lI(Unknown Source)
com.aspose.pdf.internal.l0j.le.lI(Unknown Source)
com.aspose.pdf.internal.l0u.l0if.lI(Unknown Source)
com.aspose.pdf.internal.l0j.lc.lI(Unknown Source)
com.aspose.pdf.internal.l0j.le.lI(Unknown Source)
com.aspose.pdf.internal.l0u.lk.lI(Unknown Source)
com.aspose.pdf.internal.l0j.lu.lI(Unknown Source)
com.aspose.pdf.internal.l0j.le.lI(Unknown Source)
com.aspose.pdf.internal.l0u.l0l.lI(Unknown Source)
com.aspose.pdf.internal.l0j.lv.lj(Unknown Source)
com.aspose.pdf.internal.l0j.lv.lI(Unknown Source)
com.aspose.pdf.internal.l0j.le.lI(Unknown Source)
com.aspose.pdf.internal.l0u.lh.lI(Unknown Source)
com.aspose.pdf.internal.l99t.lk.lI(Unknown Source)
com.aspose.pdf.internal.l0u.lh.lI(Unknown Source)
com.aspose.pdf.internal.l99t.lk.lf(Unknown Source)
com.aspose.pdf.internal.l99t.le.lk(Unknown Source)
com.aspose.pdf.internal.l15p.lv.lI(Unknown Source)
com.aspose.pdf.internal.l15p.lb.lf(Unknown Source)
com.aspose.pdf.internal.l15t.lj.lI(Unknown Source)
com.aspose.pdf.internal.l0j.lf.lI(Unknown Source)
com.aspose.pdf.l4j.lI(Unknown Source)
com.aspose.pdf.l4j.lI(Unknown Source)
com.aspose.pdf.ADocument.lj(Unknown Source)
com.aspose.pdf.ADocument.lj(Unknown Source)
com.aspose.pdf.ADocument.lf(Unknown Source)
com.aspose.pdf.Document.lf(Unknown Source)
com.aspose.pdf.ADocument.save(Unknown Source)
com.aspose.pdf.Document.save(Unknown Source)
I have confirmed that the font files do exist and can be opened successfully. What should I do?
Thanks!
Here is the link to the PDF I’m trying to convert. I don’t think there’s anything special about this PDF. simple.pdf (29.5 KB)