+ Start a Discussion
dawnzdydawnzdy 

Solved: Saving renderAs PDFs as document and attachments

Hi, I am trying to save the visualforce page (rendered as PDF) as document and attachment. I was able to insert them but have problem opening the link.

 

 

When I try the document, it says: File does not begin with '%PDF-'

When I try the attachment, it says: unable to process request, please try again later. Any suggestions?

 

I have read through this link and was using the similar code, not sure why doesn't work.

 

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=13549#M13549

 

 

 

Thanks for your help and reply!

 

Dawn

Message Edited by dawnzdy on 06-05-2009 01:31 PM
Best Answer chosen by Admin (Salesforce Developers) 
XactiumBenXactiumBen

I usually put the document's MIME Type in the ContentType field (i.e. 'application/pdf', 'image/jpg' etc.) and this seems to work.  I think this field requires the MIME Type whilst the Type field requires the file extension.

 

When I mentioned posting up your code I meant how you are getting the page and sticking it into the actual document or attachment? It could be that you weren't setting up the data correctly for the document/attachment.

All Answers

dawnzdydawnzdy

It's kind of wierd, when I tried with other records, that function worked fine.

 

Only doesn't work for this one.

 

I would still like to know the answer if you have encountered such problem.

 

Thanks,

Dawn

XactiumBenXactiumBen

This usually means that your visualforce page isn't rendering as a pdf at all but you are saving it as a Document/Attachment with a content type of 'application/pdf'. 

 

If you post up your current code I might be able to see a problem with how you're trying to implement saving your visualforce page as a pdf.

 

Have you tried opening up the page in the browser to make sure it is loading as a pdf properly?

dawnzdydawnzdy

Hi ,

 

   Thanks for your reply!

 

   Yes, I did tried to open the page itself and it's working.Here's the page rendering code.

 

 

<apex:page standardController="FinanceInvoice__c" extensions="InvoiceAccountController" renderAs="pdf">

 

   You mentioned about contentType, one thing to confirm:

   

   I found many examples using different words for pdf for this field, like :  'application/pdf', 'pdf'. Is there any difference? Or they should be used in different senarios? There is also another field, Type. How is it differenciate from ContentType?

 

   I don't think there should be much problem in the code, since it works fine for many other invoices.But there may be some potential bug for certain type of record, like the one I encoutered.

 

   Thanks for reply & looking forward to your reply!

 

 

Dawn

 

Message Edited by dawnzdy on 06-05-2009 11:12 AM
XactiumBenXactiumBen

I usually put the document's MIME Type in the ContentType field (i.e. 'application/pdf', 'image/jpg' etc.) and this seems to work.  I think this field requires the MIME Type whilst the Type field requires the file extension.

 

When I mentioned posting up your code I meant how you are getting the page and sticking it into the actual document or attachment? It could be that you weren't setting up the data correctly for the document/attachment.

This was selected as the best answer
dawnzdydawnzdy

Oh, got it! Maybe I used  the wrong contactType for attachment, or it's salesforce's exception.

 

Just tried again, it works for all records.

 

Thanks so much ! Both your answer and the link in my first post are very helpful!

 

Dawn

Message Edited by dawnzdy on 06-05-2009 11:32 AM
TLFTLF

Hi,

 

Any idea why the URL in the first post in this thread is no longer valid?

Rocks_SFDCRocks_SFDC

Hello Everyone,

 

Could anyone share the code that will achieve when ever we click on the button at detail page, a render as pdf file will open will save into attachments related list

 

Thanks,

Anil