I would like to use Aspose.Words for Java on AWS Lambda to convert PDF with a specific font. I need to import the font by using FileFontSource function but I found this does not work on AWS lambda but work on my local computer. I already confirmed the package certainly includes the font file. Do you have any idea to resolve this?
FileFontSource:
Source code:
FontSourceBase[] originalFontsSources = FontSettings.getDefaultInstance().getFontsSources();
FolderFontSource folderFontSource = new FolderFontSource(“./fonts”, true);
for (PhysicalFontInfo fontInfo : for (PhysicalFontInfo fontInfo :
FontSettings.getDefaultInstance().getFontsSources()[0].getAvailableFonts()) {
System.out.println(fontInfo.getFullFontName());
};
@katsuya0515,
Please copy the required font files from your local machine into a separate folder inside AWS Lambda and try running the following code of latest 21.3 version of Aspose.Words for Java:
Document doc = new Document("word.docx");
FontSettings fontSettings = new FontSettings();
addFontFolder(fontSettings, myDir + "CustomFonts/");
doc.setFontSettings(fontSettings);
doc.save("output.pdf");
private static void addFontFolder(FontSettings fontSettings, String folder)
{
FontSourceBase[] fontSourceBases = fontSettings.getFontsSources();
FontSourceBase[] newFontSourceBases = new FontSourceBase[fontSourceBases.length + 1];
System.arraycopy(fontSourceBases, 0, newFontSourceBases, 0, fontSourceBases.length);
newFontSourceBases[newFontSourceBases.length - 1] = new FolderFontSource(folder, true);
fontSettings.setFontsSources(newFontSourceBases);
}
Do you see any missing fonts related warning messages? Please check the following articles:
1 Like