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
BrianWKBrianWK 

Renderas="pdf" returns visualforce error index: 0, size:0

I have a visualforce page that renders perfectly fine in HTML. However, when I set Renderas="pdf" I get a gray header box labelled "VisualForce Error" and below it "Index:0, Size:0"
 
Are there any gotchas for renderas="pdf" that would return this error? I've done other pages that did similar functions and rendered fine as a pdf. The only thing I can think of is I have a lot of HTML and some Javascript on the page. I tried removing the javascript - but still receive the index:0 size:0 error.
 
What would cause the page to look great in HTML but not work in PDF?


Message Edited by BrianWK on 12-18-2008 10:09 AM
JeremyKraybillJeremyKraybill
Brian, yes, you almost certainly are running into the same issue I ran into about a week ago. There is a known but undocumented limitation of renderAs="pdf" in that it does a redirect, which causes you to lose controller state that you expect to remain there.

See this thread for my discussion of it. I ended up implementing a solution that is very similar to what I described -- basically PDF requests first hit a non-PDF page with a controller to gather the data they need, then save it into an SObject, and then redirect to the .page file which has renderAs="pdf", with the ID of the persisted SObject passed via URL.

I have logged this as a case with customer support, and Doug Chasman has already coded up a fix for it which hopefully we will see in the spring release!

Jeremy Kraybill
Austin, TX
BrianWKBrianWK
Jeremy,
 
Thanks for replying and the notification! I was searching the boards all over the place for the error and on PDFs (there are amazing number of PDF posts).
 
I've already promoted your idea. Hopefully this gets into the spring 09 update if not earlier. I may have to try your work around since our president needs this functionality ASAP. Did you build a brand new custom object to handle the PDF setup or do you use existing objects and simply removed the records afterwards?
 
Thanks again!
 
Brian
JeremyKraybillJeremyKraybill
I created a custom object explicitly for this "session data", it's a simple master-detail record where the ID of the master is passed around, and the children are simple 2-field key-value pair objects. But you could use anything, I just opted for something that would be general purpose. I expect to re-use it for some other long-lived persistent data. One of the future things I expect to do is extend User to point to a single Id of one of these session records, which will allow for longer-term persistence of random session data (e.g. user preferences, etc) without having to extend the heck out of User with custom fields.

HTH.

Jeremy Kraybill
Austin, TX
dchasmandchasman
FYI I committed the fix to support chaining POSTs in PDF generation to the Spring '09 (hits test.salesforce.com early next year). I also corrected a long standing issue with error handling - basically if you get a failure when renderAs="pdf" the generated PDF will contain the error page as a PDF instead of a blank page as it does currently...
JeremyKraybillJeremyKraybill
Awesome, thanks! Looking forward to it!

Jeremy Kraybill
Austin, TX
JMPlayer22JMPlayer22

I'm still getting this error...was this fixed?  I'm trying to sort some OpportunityLineItems and in order to do that I had to use a custom component in the visualforce page...works fine without renderAs="PDF"...but once I add that in there, it gives me this visualforce error...

 

???