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

Free Support Forum - aspose.com

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.