7

I have pdf blob data returning in my webservice.. I want to display this blob data as pdf in visualforce page. Is there any way to render the page as pdf with this blob data looking like pdf page. Currently, it is printing the base64 encoded string in the pdf page. But I want to convert pdf blob base64 encoded data as true pdf page

<apex:page renderAs="pdf">
     {!pdfBlobData}
</apex:page>

Please correct me if I am wrong or suggest me a way to display this.

  • can you post/Suggest how you solved the above issue? Facing the Same issue – SFDC Apr 26 at 10:35
2

Visualforce does not emit binary data. As such, there is no direct way I'm aware of to render a PDF blob to the user using Visualforce.

The one semi-exception I know of is that you can cause a browser to render an image file (not PDF) using base 64 data URL's.

Your best bet is probably to save the PDF blob as an Attachment object, and then redirect the user to the "View Attachment" platform URL.

  • Yeah that's true.. But I need to find a solution to make this happen. Any other way I should be looking for? – NoNicknameSFDC Apr 29 '15 at 6:46
0

Summary of your situation

I try to understand the issue in general. A web service returns a blob of data, which is actual a pdf. The pdf should be presented to the user as a pdf.

Potential solutions

Store the PDF Blob as an attachment

  1. Download the PDF from your web service and store the received blob as attachment.
  2. Redirect the user on your VF Page to the generated attachment.

Use Javascript to present the pdf blob

On your visual force page include the blob via Javascript as a new object.

var content = URL.createObjectURL(blob); // your Blob
$("embed").attr("src", content); // add the blob to your VF page
<embed src="" width="200" height="200"></embed>
-2

As an option you can convert your blob to string and then display it that way.

public String BlobText{get{return pdfBlobData.Tostring();}}

<apex:page renderAs="pdf"> {!BlobText} </apex:page>

  • This gives ` common.apex.runtime.impl.ExecutionException: BLOB is not a valid UTF-8 string ` exception. I had tried this before. – NoNicknameSFDC Apr 29 '15 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.