function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

PDF generation hangs


 I have a program feature that generates PDF documents via the standard Visual Force 'renderAs="PDF"' mechanism. This feature does not work reliably for 'larger' documents (i.e. 50 pages). By 'reliably' I mean that I can run PDF generation 10 times, and it will work successfully 3-5 times out of these 10. The rest of the time, after a 3+ min delay, I get the following error message:

"PDF generation couldn't complete because the request took too long. You are using components that are not fully supported by PDF generation, please consult the documentation for a list of unsupported components."

I've reviewed the page (it's a long and ugly beast, so am not posting it here), but am not seeing anything unsupported or suspicious.  This test can be run on the exact same object, with the exact same data, 10 times in a row, and the results are non-deterministic.   The fact that it works for some runs, but not others makes me suspect that this doesn't have to do with any specific page markup, but I could be wrong.

When I look at the system log output, I see that the controller code for this page is done after 12-15 sec. After that, there's a long delay--when the PDF is rendered successfully, the delay is about 30-40 sec. When it fails, as above, it is 3+ min.

It appears that something is making the PDF rendering engine go haywire, but I have not been able to figure out what it may be, and therefore, how to work around it.

If you have the system log open, you can see that the last statement from the controller (CODE_UNIT_FINISHED|StaticResourcePick <init>) is usually executed a long time before the CUMULATIVE_LIMIT_USAGE line. 



Does anyone have any ideas/suggestions?


Well, you call it a "long and ugly beast" so that right there might be your problem.  From the error message it sounds like you are using unsupported components, even though you can't pick them out.  Can you simplify your page at all?  Are you pulling in custom components that are using unsupported components?  The fact that you're getting that particular flavor of an error message suggests to me that it actually is a problem with your markup (although yeah, you could argue that the PDF generation should be more consistent).


Turning HTML into something printable can be a little fragile.  Sometimes it can get hung up on simple things like invalid HTML (like it's expecting that you have only <tr> or <td> type tags in your <table> but instead it starts finding <div> and <span> tags).  Or it can hang while pulling in giant CSS files or static resources.


I would highly suggest not sending a "long and ugly beast" to the PDF generator and instead verifying that your markup is well formed, valid HTML, and doesn't use any unsupported Visualforce tags.


This is probably not the answer you want to hear but the PDF stuff can be a little difficult to debug.


The browser you're using may contribute.


While I was doing some data imports for my organization, I had problems with timeouts -- sometimes the longer uploads would fail, sometimes they wouldn't.  That was in Firefox, so I tried using Internet Explorer instead and was able to not only get all the uploads on the first try, but managed one bigger one (Saving me having to split it into smaller files like I'd been considering)  I've also had issues with Firefox failing on local php scripts run on large datafiles, where it just took so long processing that it timed out prematurely.

If you haven't done so yet, I'd suggest trying the same operation in a different browser (Internet Explorer seems to have much longer timeout values, a 3 minute load time could easily be timing out in Firefox even if the page hasn't actually failed) and seeing if that impacts your results.


Hi Jill,


No, that's not quite the answer I'd hoped for, but in your place, I might be giving the same answer!  :smileysad:


Your suggestions all make sense, but with the following observations:


- Other PDF pages in our app work fine, using the same markup

- This same page works fine on 'simpler'/'smaller' jobs, using the same markup

- This same page works fine on the same job (obviously using the same markup)--sometimes


Given that, would you think that it's something in the markup itself that's causing problems?  The component that is listed in the 'use with caution' category in the PDF 'best practices' is 'dataTable'--but what does 'use with caution' mean??


Are there any tools that could be used (on the SF side) to help pinpoint the problem?


Thank you so much for your help; I look forward to any more insights you may have...








Thank you for the suggestion; I'll give it a try.  However, since the message that I'm getting seems to be coming back from SF (with some SF-specific text; e.g. about 'unsupported components'), it doesn't seem like this is a browser-timeout issue.  It would appear that it's SF that's timing out, not the browser.  No?



It is unlikely to be the browser, but still may be possible if Salesforce is monitoring a script for completion and that script is timing out, the error message could come from Salesforce still. Since the problem is intermittent and those can be really hard to diagnose, it's just something to remove one of the possible causes and help narrow down where it may be coming from. I don't have enough Salesforce experience to provide anything more in depth to check. Good luck!



I've made some progress on this by removing apex:form (which shouldn't have been there in the first place) and replacing outputField tags with outputText.  This has improved things greatly for a lot of previously problematic records.


However, there are still some pages, for which I've done the above, and I still sometimes (for bigger jobs) get the error:


PDF generation failed. Check the page markup is valid.


The only potentially problematic element on this page that I can see is dataTable, which the docs say 'use with caution'.  Can anyone:

1) Explain what 'use with caution' means

2) Suggest a way to troubleshoot it?

3) Suggest a way to iterate over a set of records in a PDF document without using dataTable?  This seems to be such a common requirement...


Thanks in advance,




I got the same problem today, and PDF generation was all fine till yesterday. So I Knew the code Mark up was correct. So I did troubleshoot the entire code line by line. I commented out whole code and started uncommenting line by line. And the problem was with the secuitry settings. If we are trying to display/view an Object's records on a pdf which we do not have access to, we simply get this error "PDF generation failed. Check the page markup is valid.


I ran into this issue, and found out that the map i was using to feed one of my components on my VF/PDF document contained null keys.


I found out that this error PDF generation failed. Check the page markup is valid. might come from unorganized html tags. In my case it was something like this







here there is a mising td .. when I added it it worked. 

Hope this helps


I had the same issue come up. The culprit was


<apex:tabPanel> </apex:tabPanel>


I took that out and the error went away.


If you look at the documentation,  here tabPanel is one of the components that is not safe ot render as PDF along with a rather long list of other components. It's inconsistent since one of the unsafe components is pageblock and I have that in my VF page.