IWarningCallback Does Not Work During PDF Conversion

Hello,

We need to capture all font substitutions when converting a PPTX to PDF. However, setting a IWarningCallback while converting a PPTX to PDF does not seem to work.

This behavior can be seen in the latest Aspose Slides for Java version 20.5, the attached NonExistingFonts.pptx file and the following Java code:

final String pptxFile = [PATH] + "NonExistingFonts.pptx";
final String pdfFile = pptxFile.replace(".pptx", ".pdf");

final IWarningCallback warningCallback = new IWarningCallback() {
   @Override
   public int warning(IWarningInfo warning) {
       System.out.println("* * * * * Got Warning Callback:\n  " +
                          warning.getDescription());
       return ReturnAction.Continue;
   }
};

// Load the PPTX
Presentation ppt = new Presentation(pptxFile);

// Save the PPTX as PDF
System.out.println("\nCallback output from Presentation SAVE (as PDF):");
PdfOptions saveOptions = new PdfOptions();
saveOptions.setWarningCallback(warningCallback);
ppt.save(pdfFile, SaveFormat.Pdf, saveOptions);

System.out.println("\nCompleted saving of: " + pdfFile);

The above produces the following output in the console:

Callback output from Presentation SAVE (as PDF):

Completed saving of: NonExistingFonts.pdf

Since the PPTX uses two non-existing fonts we are expecting them to be reported via the callback mechanism.

Workaround:
We’ve found that if the callback is added to the LoadOptions - the font substitutions will be reported.

We can apply the workaround using the same sample code from above - but instead load the Presentation using LoadOptions with a callback as such:

System.out.println("Callback output from Presentation LOAD:");
LoadOptions loadOptions = new LoadOptions();
loadOptions.setWarningCallback(warningCallback);
Presentation ppt = new Presentation(pptxFile, loadOptions);

When this modified version is run, the following is the new output:

Callback output from Presentation LOAD:
* * * * * Got Warning Callback:
  The locking behavior of BlobManagementOptions.PresentationLockingBehavior is set to LoadAndRelease_Legacy_TemporaryDefault, which will be removed in version 17.10, and the default locking behavior will changed. Please consider KeepSourceLocked or LoadAndRelease options to choose the behavior most suitable for you.

Callback output from Presentation SAVE (as PDF):
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 1 to {Jokerman,Juice ITC,Niagara Engraved,Harrington,Playbill,Colonna MT,Bodoni MT Poster Compressed}
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 1 to {Jokerman,Juice ITC,Niagara Engraved,Harrington,Playbill,Colonna MT,Bodoni MT Poster Compressed}
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 1 to {Jokerman,Juice ITC,Niagara Engraved,Harrington,Playbill,Colonna MT,Bodoni MT Poster Compressed}
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 2 to {Arial,Cambria Math,MS Gothic,Gulim,Arial Unicode,SimSun,Segoe UI Symbol}
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 2 to {Arial,Cambria Math,MS Gothic,Gulim,Arial Unicode,SimSun,Segoe UI Symbol}
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 2 to {Arial,Cambria Math,MS Gothic,Gulim,Arial Unicode,SimSun,Segoe UI Symbol}
* * * * * Got Warning Callback:
  Font will be substituted from Bad Font 2 to {Arial,Cambria Math,MS Gothic,Gulim,Arial Unicode,SimSun,Segoe UI Symbol}

Completed saving of: NonExistingFonts.pdf

Unfortunately, we cannot use this workaround at this time. It would be preferable that the callback feature work with SaveOptions without requiring the callback on the LoadOptions.

Environment Details:

  • Aspose Slides for Java 20.5
  • Java version 1.8.0_211
  • Windows 10 OS (but also reproducible under Linux).

File description in the NonExistingFonts.zip (24.5 KB) attachment:

  • NonExistingFonts.pptx: Presentation used by the sample code. Note that it constrains 2 non-existing fonts.

Thank you!

@oraspose,

I have observed the issue shared by you. In fact what you are calling a workaround approach for getting warning callbacks for font substitution is actual way to implement. I suggest you to please visit this documentation link for your kind reference.

Thanks for your reply Mudassir.

The main problem is that the routine which generates the PDF, is not responsible for loading the PPTX (i.e. it already has a Presentation instance). Reloading the PDF is not an option. Additionally, there does not seem to be any Slides APIs to get the LoadOptions from a Presentation instance.

It is misleading for the PdfOptions class to offer the setWarningCallback API - when (apparently) it does nothing. The API documentation for SaveOptions makes no mention of this behavior. Even the documentation link you provided says nothing indicating that the callback works only when set via the LoadOptions - and that it has no effect on the SaveOptions.

Lastly, while we certainly understand that Aspose Words and Aspose Cells are different products, there are similar patterns in the way the Libraries work. However, in Aspose Words & Cells, their corresponding SaveOptions.setWarningCallback APIs - do work without the need to set it via their LoadOptions.

Would you consider changing the behavior of the SaveOptions.setWarningCallback API? If not, would you consider exposing a new API that provides the LoadOptions from a Presentation? If not, could you suggest another workaround for capturing font substitutions - that does not require reloading the Presentation?

Thank you.

@oraspose,

I have observed your suggestions w.r.t setting WarningCallback and its placement in different class as compared to present one. I have also observed your comparison w.r.t Aspose.Cells and Words. I have created a ticket with ID SLIDESJAVA-38127 as enhancement to observe your requirements and consider similar implementation as available in other APIs. Still, our team will internally make better decision about it and we will share feedback with you as soon as it will be available.

Hello @mudassir.fayyaz
Any update to this ticket ? Is is possible to capture the warnings of font substitution during the save to PDF operation ?

@vedjaipraful,
Thank you for the inquiry. I’ve requested plans for this issue from our development team. We will reply to you as soon as possible.

I have tried to put some sample code for collecting the warnings. I observe that there is no filtering mechanism for the warning messages for font substitution.
Here in the aspose.slides we do not see a dedicated warning for font substitution. This is unlike the WarningType enum for cells/word.

Could you please help in understanding how to filter in only the font substitution warnings ?

@vedjaipraful,
You are right, Aspose.Slides doesn’t make it easy to filter font substitutions by WarningType values yet. I added a ticket with ID SLIDESJAVA-38697 in our issue tracking system. Our development team will consider such an enhancement. We will inform you of any progress.

As a workaround, you can try to parse results of IWarningInfo.getDescription method like this:

class SubstitutionWarnings implements IWarningCallback
{
    public int warning(IWarningInfo warning)
    {
        if (WarningType.DataLoss == warning.getWarningType() && warning.getDescription().contains("Font will be substituted"))
        {
            System.out.println(warning.getDescription());
        }
        return ReturnAction.Continue;
    }
}

Documents: Getting Warning Callbacks for Fonts Substitution

@vedjaipraful,

The issue SLIDESJAVA-38127 will be investigated next week. After that, we will be able to share our plans for such an update.

Any update on this @Andrey_Potapov
Or do I have to continue banking on the load callback ?

@vedjaipraful,
I’ve requested any news on this issue from our development team. We will reply to you soon.

The issues you have found earlier (filed as SLIDESJAVA-38127) have been fixed in Aspose.Slides for Java 22.4 (ZIP).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.

@oraspose, @vedjaipraful,
With Aspose.Slides 22.4, you can use the IWarningCallback interface while converting a presentation to PDF. The following code snippet shows you how to detect font substitutions:

Presentation ppt = new Presentation("NonExistingFonts.pptx");
try {
    PdfOptions saveOptions = new PdfOptions();
    saveOptions.setWarningCallback(new WarningCallbackHandler());
    ppt.save("NonExistingFonts.pdf", SaveFormat.Pdf, saveOptions);

    String[] results = ((WarningCallbackHandler)saveOptions.getWarningCallback()).
            warnings.stream().filter(x -> x.contains("Font will be substituted")).toArray(size -> new String[size]);

    Arrays.stream(results).forEach(System.out::println);
} finally {
    if (ppt != null) ppt.dispose();
}
class WarningCallbackHandler implements IWarningCallback
{
    ArrayList<String> warnings = new ArrayList<String>();

    public int warning(IWarningInfo warning)
    {
        warnings.add(warning.getDescription());
        return ReturnAction.Continue;
    }
}

Hello @Andrey_Potapov
Thank you for sharing this update. Really appreciate your help.
We will try this code and confirm with the latest release you have mentioned.

@vedjaipraful,
Thank you for using Aspose.Slides. We will be waiting for your feedback.