[Ultimate PDF] How to handle exceptions while using Ultimate PDF
Reactive icon
Forge component by Leonardo Fernandes
Application Type

Hello Everyone,

We have a scenario where if the screen gives any exception or timeout error, the Ultimate PDF component still returns the binary output file with error screenshot.

We want to show the error message to users if there was any exception or timeout error in loading the screen. 

Also we have some timers where we generate some documents and save them in the database. Currently we are checking if the output binary file is not null binary then we save this information in the database. 

However we do not want to save any document with error, so we were looking if this component has any way to identify if the screen was converted to PDF without any exceptions? or if it can be enhanced to return the a flag as output parameters indicating there was no exceptions in the screen while loading the screen for PDF generation.

Attaching a sample output with exception.



Ultimate PDF with exceptions.jpg

Hi Zubair,

I've faced this same issue in one of my projects, and this is how I handled it:

  1. First you have to create a new application whose only purpose is to generate the reports.
  2. In that application, create an "Error" screen with nothing in it. The objective is for the rendered screen to be as small as possible.
  3. Change the application's global exception handler (usually found in the "Common" flow) to something like this:
  4. When calling the UltimatePDF action, check for the size of the resulting binary using  the BinaryData.BinaryDataSize action (I believe the BinaryData extension is a system component). So it would look like this:

This allows you to detect when there was an error generating the PDF and act accordingly.

Please be advised that you might have to ajust the number of KBs used in the comparison, depending on the size of your reports. In my case, it was safe to assume that a file with 10KB or less was always the result of an exception.

Dear Aurelio, Thanks for your response, we also thought about this option however with this approach we have to ensure that the actual file size does not come less than predefined value of e.g. 10KB. We shall check if all our documents can fit in this approach and implement it accordingly. Regards, Zubair
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.