I’m trying to generate a pdf on Anvil using a background task. Unfortunately, it takes sometimes to generate the pdf, so it raised this error:
Exception: PDF generation failed: Components did not load within allowed time.
at /downlink/anvil/pdf.py, line 17
called from /downlink/anvil/pdf.py, line 43
If you did have the special use case like @stefano.menci described you would be out of luck getting the users browser or anvil itself to render your super long PDF.
However if this was your special case, you could have a special solution, using anvil to render multiple pdfs in smaller files and then sending them over uplink if you are on the free plan, or using PyPDF2 in a server module if you are on the paid plan.
Once you sent all the separately generated PDF’s to an uplink or a server module they could be combined using PyPDF2.PdfFileMerger() as described in this stackoverflow thread:
It also says it takes file handlers, so I suggest sending the files as anvil.media objects and creating a filestream using io.BytesIO( anvil.media.get_bytes() ) for each file to be recombined, keeping everything in memory instead of writing anything to disk.