You need to sign in to do that
Don't have an account?

Sending pdf in web service
We are rendering a page as the pdf in visualforce.
As a part of an interface, this pdf needs to be sent a response to a web service.
Any pointers on how this can be done?
are there any salesforce.com specific restrictions or implementation considerations that need to be thought about before implementing the interface?
Thanks a lot,
Pooja
Experts on the subject please correct me if I'm wrong but if you're talking about a SOAP webservice then you'd need support for SOAP Attachments (http://www.w3.org/TR/SOAP-attachments). Salesforce does not have that at this point in time.
What you could do is expose your pdf via VF and Sites (make sure you put in a security check with a generated key or something) and send the link + key over with the webservice. The receiving end can then pull in the document as needed.
David
No need for SOAP attachments, your apex web service can return binary data in base64 format like the regular api does, see the Blob type in apex.
Thanks a lot for the quick response.
Can serialization help in any way for sending the pdf in the web service?
How will the .NET client be able to access visualForce links? Can you refer me to links that explain how VF can be exposed outside salesforce.com? We need to implement a batch printing functionality. The .NET webservice sends in a list of 50 objectIds and we need to send back 50 pdfs to them. .NET client will direct it to the printer.
Each pdf is about 60KB. So we should be within the limits of the response size. But do you see other problems with this approach? I am not sure how we can save the VF page rendered as the pdf and send it in any way to a web service.
Thanks,
Pooja
Thanks.
Whenever i search for saving VF rendered as PDF In the attachments, I am getting examples of saving it as email attachments. Will the same logic work for storing it as attachments on the object.
The following function will be called in a loop for different quoteIds.
public blob getpdfContent(Id quoteId)
{
PageReference pdf = Page.attachmentPDF;
pdf.getParameters().put('quoteid',quoteId);
pdf.setRedirect(true);
Blob b = pdf.getContent();
return b;
}
AttachmentPdf is associated to the custom controller which has the logic for rendering it as a pdf.
Also, does the same rule apply for sending word documents as responses to web services?
Thanks a lot. Your responses have been tremendous help
Pooja
public PageReference attach_Your_Document(Id RecordId) { // Get the page definition PageReference pdfPage = Page.PageNameOftheVisuaforcePageRenderedAsPDF; // set the Record id on the page definition (To execute the vf page with the recordId pdfPage.getParameters().put('id',RecordId); // generate the pdf blob Blob pdfBlob = pdfPage.getContent(); // create the attachment against the quote Attachment a = new Attachment(parentId = id, name=name + '.pdf', body = pdfBlob); // insert the attachment insert a; return null; }
This is a sample code to attach documents for a record Id
Thanks a lot for the response.
I was able to add an attachment using the code you gave.
However when I return a blob in a web service and test it using SOAP UI I get the following error
'The child of the Envelope element must be either a Header or Body element'
The web service is as follows:
Please advise.
Thanks,
Pooja
my bad! I was sending the XML request incorrectly.
I get a response back which appears gibberish.
But I guess thats how base 64 encoded result will look like.
Thanks,
Pooja
Hi All,
I have to do same thing (read PDF returned from the external webService, within Salesforce). Is there any solution ?
Thanks.
Hi
Did you got any solution for the problem? Can you please share it.
Thanks