Free Support Forum - aspose.com

KeyNotFoundException occurs when converting PPTX to PDF

image.png (271.7 KB)
https://tezign-assets.oss-cn-beijing.aliyuncs.com/572da48221b7bffe6c9de3745d4380c6.pptx

public static void main(String[] args) {
final Presentation pres = new Presentation("/Users/zyx/Downloads/打造企业级内容的数字新基建.pptx");
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setDefaultRegularFont(“Arial”);
final IFontsManager fontsManager = pres.getFontsManager();
// 获取ppt里面所有的字体
IFontData[] embeddedFonts = fontsManager.getFonts();
FontsLoader.loadExternalFonts(new String[]{FileConvertConstant.FONT_PATH});
if(embeddedFonts.length > 0){
for (IFontData embeddedFont : embeddedFonts) {
final String fontName = embeddedFont.getFontName();
// 如果ppt中字体在本地不存在
if(!FontConfig.getLocalFontsSets().contains(fontName)){
// 最后指定默认的
fontsManager.replaceFont(embeddedFont, new FontData(FileConvertConstant.DEFAULT_FONT));
}
}
}
pres.save("/Users/zyx/Desktop/aaa.pdf", SaveFormat.Pdf,pdfOptions);
}

@zyx,
Thank you for the query. Unfortunately, I have not managed to reproduce the error. To investigate this case further, please share and specify the following:

  • comprehensive code example (FontConfig is an unknown symbol)
  • your external fonts that code example loads (FileConvertConstant.FONT_PATH)
  • your default font for replacing (FileConvertConstant.DEFAULT_FONT)
  • version of the OS on which the error appears
  • version of JDK that your application used
  • version of Aspose.Slides you used

But first, please check the issue with the latest version of Aspose.Slides.

public static void main(String[] args) {
final Presentation pres = new Presentation("/Users/zyx/Downloads/打造企业级内容的数字新基建.pptx");
PdfOptions pdfOptions = new PdfOptions();
pres.save("/Users/zyx/Desktop/aaa.pdf", SaveFormat.Pdf,pdfOptions);
}

image.jpg (305.1 KB)

jdk1.8

com.aspose
aspose-slides
21.4
jdk16

@zyx,
Please specify the version of the operating system in which the error occurs.

image.png (59.0 KB)

It has nothing to do with the operating system, I failed on my own computer and cloud server

@zyx,
I logged the issue in our tracking system with ID SLIDESJAVA-38549. Our development team will investigate this case. I will inform you of any progress.

The issues you have found earlier (filed as SLIDESJAVA-38549) have been fixed in this update.