[Ultimate PDF] Using ScreenshotToPNG twice in combination with Timer = time-out
Forge component by Leonardo Fernandes
Application Type
Traditional Web

We've been using UltimatePdf for some image-heavy PDFs, ~25MB on average total size. We use ScreenshotToPNG for some post-processing of certain images.

Because we have to generate different variants of the same PDF at the same time, we converted to using Timers (one timer for each variant) so they can be generated at the same time.

Unfortunately we receive a time-out for only one timer after ScreenshotToPNG tries for about 112 seconds. This is the only generate action that uses the ScreenshotToPNG action twice in a row, in certain cases. In case the generate action only needs one screenshot action, it works is fine. Also, when we trigger our generate action manually via a button instead of a timer, everything renders and converts fine.

The viewport width and height passed is always below 1800, and the resulting binary does not exceed 300KB. So no extreme rendering in this aspect.

I suspect some memory issue and/or browser sessions that conflict with each other. But I cannot explain why it works in the manual way without using a timer then.

Did anyone encounter this issue or has tips to solve this?


Hi Geertjan,

Please have a look on this post [Ultimate PDF] How to generate PDF for non anonymous web screens ? | OutSystems , it seems there is a workaround/discussion with regards to the timer approach.

Hope this helps,

Thank you and kind regards,

Chris

Thank you for your reply.

The problem is not user or session related because other pdfs actually render fine, those in which the ScreenshotToPdf action is not used twice. We already pass a token to be checked when generating.

We use the screenshot functionality for just one or two pages in a 40+ page pdf. Without this particular page, it generates in around 30 seconds. Including this action (twice) results in a time-out of 2 minutes. Mind you, this only occurs when generating via a timer.

With some additional testing we think the long generation time is not related to the ScreenshotToPNG function per se. 

The difference between triggering the server action via a button (user action) OR via a timer (system action) is huge: 60 secs vs 130+ secs. 

My suspicion of a memory issue or any other resource allocation stays. Maybe a system triggered action has a different way of managing system resources. I couldn't find any Outsystems documentation on this.



"My suspicion of a memory issue or any other resource allocation stays. Maybe a system triggered action has a different way of managing system resources. I couldn't find any Outsystems documentation on this. "

My suspicion of memory shortage remains. When generating a large, content-heavy PDF, it fails to generate. The generic error being thrown is not very useful:

"UltimatePDF: An error occurred while generating the pdf "

Are there any insights in (maximum) memory usage and/or internal errors of the extension itself?

To follow up on this:

When diving into the UltimatePDF logic we found there are multiple places where Service actions are used. 

Although Service action timeouts are not explicitly mentioned, I assume they're handled as a Web service. According to Outsystems documentation these always have a timeout of 100 secs. https://success.outsystems.com/Support/Enterprise_Customers/Maintenance_and_Operations/Timeouts_Under_the_Hood

So if I'm not mistaken, in short: whenever a PDF takes more than 100 seconds to generate, UltimatePDF will timeout regardless of any SetRequestTimeout you added before calling the PrintToPDF() action.

mvp_badge
MVP

Hi Geertjan Jacobs, I wasn't aware of that limitation of service actions. Let me see what I can do.

Can I ask if it would be possible to optimize the PDF generation? What's the reason it takes so long? Is it too many database queries being executed, integrations taking too long, too many pages in a single PDF?

mvp_badge
MVP

Geertjan could you check if the 4.0.5 version fixes these timeouts?


Thanks! I will update and check as soon as I can find the time.

"Can I ask if it would be possible to optimize the PDF generation? What's the reason it takes so long? Is it too many database queries being executed, integrations taking too long, too many pages in a single PDF?"

Very content heavy. On average 6 smaller pictures per page, a couple of full page images, web calls to APIs, 50-100 pages per PDF and to top it off some realtime content validations.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.