We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

IWarningCallBack does not work when I convert PPT to PDF

thank you,but I know this, but what I am confused about is that IWarningCallBack does not work when I convert ppt to pdf

public class Ppt2PdfConversionImpl implements AsposeConversion{

private final FontUtils fontUtils;

public static void main(String[] args) {
    ConversionDTO conversionDTO = new ConversionDTO();
    conversionDTO.setTargetPath("/Users/zyx/Desktop/");
    conversionDTO.setFileName("字体修正后-2.pdf");
    conversionDTO.setSrcPath("/Users/zyx/Downloads/线上端内互动案例.pptx");
    Ppt2PdfConversionImpl ppt2PdfConversion = new Ppt2PdfConversionImpl(null);
    ppt2PdfConversion.conversionFile(conversionDTO);
}

@Override
public String conversionFile(ConversionDTO conversionDTO){
    final String targetPath = conversionDTO.getTargetPath();
    String savePath = null;
    final String srcPath = conversionDTO.getSrcPath();
    log.info(">>>>开始解析ppt>>>"+srcPath);
    savePath = targetPath + conversionDTO.getFileName();
    final Presentation pres = new Presentation(srcPath);
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.setDefaultRegularFont(FileConvertConstant.DEFAULT_FONT);
    pdfOptions.setWarningCallback(new HandleFontsWarnings());
   
    pres.save(savePath, SaveFormat.Pdf,pdfOptions);
    return savePath;
}

private class HandleFontsWarnings implements IWarningCallback
{
    public int warning(IWarningInfo warning)
    {
        log.info(JSON.toJSONString(warning));
        return ReturnAction.Continue;
    }
}

}

it log nothong

@zyx

Your query is related to Aspose.Slides. So, we are moving your post to Aspose.Slides forum where you will be guided appropriately.

@zyx,
To investigate this case, please share and specify the following:

  • The presentation file for reproducing the problem
  • Your output PDF file
  • The version of Aspose.Slides you used
  • The version of the operating system on which the problem occurs

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

https://tezign-assets.oss-cn-beijing.aliyuncs.com/线上端内互动案例.pptx

image.jpg (236.2 KB)

public class Ppt2PdfConversionImpl implements AsposeConversion{

private final FontUtils fontUtils;

public static void main(String[] args) {
    ConversionDTO conversionDTO = new ConversionDTO();
    conversionDTO.setTargetPath("/Users/zyx/Desktop/");
    conversionDTO.setFileName("字体修正后-2.pdf");
    conversionDTO.setSrcPath("/Users/zyx/Downloads/线上端内互动案例.pptx");
    Ppt2PdfConversionImpl ppt2PdfConversion = new Ppt2PdfConversionImpl(null);
    ppt2PdfConversion.conversionFile(conversionDTO);
}

@Override
public String conversionFile(ConversionDTO conversionDTO){
    final String targetPath = conversionDTO.getTargetPath();
    String savePath = null;
    final String srcPath = conversionDTO.getSrcPath();
    log.info(">>>>开始解析ppt>>>"+srcPath);
    savePath = targetPath + conversionDTO.getFileName();
    final Presentation pres = new Presentation(srcPath);
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.setDefaultRegularFont(FileConvertConstant.DEFAULT_FONT);
    pdfOptions.setWarningCallback(new HandleFontsWarnings());

    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();

            log.warn("font :{} not find",fontName);
            // 最后指定默认的
            fontsManager.replaceFont(embeddedFont, new FontData(FileConvertConstant.DEFAULT_FONT));
        }
    }

    pres.save(savePath, SaveFormat.Pdf,pdfOptions);
    log.info(">>>解析成功>>>"+savePath);
    return savePath;
}

private class HandleFontsWarnings implements IWarningCallback
{
    public int warning(IWarningInfo warning)
    {
        log.info(JSON.toJSONString(warning));
        return ReturnAction.Continue;
    }
}

}

It is obvious that there is indeed a missing font, but log.info(JSON.toJSONString(warning)); does not print anything

@zyx,
Thank you for the additional information. I will answer you a bit later.

@zyx,
Unfortunately, we can not use your code example containing the unknown FileConvertConstant symbol. Could you share a comprehensive code example without your application code to investigate the issue, please?