+ Start a Discussion
Das MDas M 

Saved PDF (VF rendered as pdf) has broken image

We are developeing a VF page where we can capture customer signature and attach it to the record.
The code is developed based from  following 2 posts.

http://corycowgill.blogspot.in/2013/12/capturing-signatures-with-html5-canvas.html
http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/


It's done it 2 steps.
First we capture the signature and save it to aatchment as png file.
Second in the Visulforce page we refer this image to include in the VF. (The singnature doc Id is passed as URL parmenter )

This is how it's referd in the VF page that is redered as PDF
 <apex:image Url="https://c.cs41.content.force.com/servlet/servlet.FileDownload?file={!$CurrentPage.parameters.fileId}"  />
 
 The fileId is the attachment ID of the signature impage

The problem we have is once this page is attached to the record the image is broken. It's not diplaying image.
If I harcode this tag like below

 <apex:image Url="https://c.cs41.content.force.com/servlet/servlet.FileDownload?file==00P55000000HHz1"  />
 
 Every thing works fine.
 
 I debugged and verified that the URL parmenter is getting the right value.
 
 I would like your help to fix this issue.
<apex:page standardController="Account" extensions="reconInventoryController"  renderAs="pdf"  >
<apex:form >



<!---
<apex:outputPanel styleClass="panelWrapper" layout="block">
    <apex:pageBlock title="Inventory Updated" >
    </apex:pageBlock>
</apex:outputPanel>
--->

    <apex:pageBlock title="{!theAccount.Name} - Inventory Dated ( {!Today()})">
  

      
         <apex:pageBlockTable value="{!inventories}" var="c">
            
             <apex:column value="{!c.Name}" />   
            <apex:column value="{!c.Pendant_Serial_Number__c}" />
            <apex:column value="{!c.Shelf_Life__c}" />
            <apex:column value="{!c.Ship_Date__c}" />
            <apex:column value="{!c.Phone_Serial_Number__c}" />
           
            <apex:column value="{!c.Data_Retrieval__c}" />
            <apex:column value="{!c.Status__c}" />
            <apex:column value="{!c.Comments__c}" />
           
        
            
        </apex:pageBlockTable>
        
       
        
    </apex:pageBlock>
    {!MySignURL}
    <!--
    <apex:image url="{!MySignURL}" width="256" height="256"/>
     <apex:image value="/servlet/servlet.FileDownload?file=00P55000000HSTHEA4"  />
    --->


    /servlet/servlet.FileDownload?file={!$CurrentPage.parameters.fileId}

 <apex:image url="/servlet/servlet.FileDownload?file={!MySignURL}" />

  <apex:image Url="https://c.cs41.content.force.com/servlet/servlet.FileDownload?file={!$CurrentPage.parameters.fileId}"  />
 
 <apex:image value="{!URLFOR($Action.Attachment.Download, $CurrentPage.parameters.fileId )}" />
    
    
     
     
    </apex:form>
    </apex:page>
Here is the screenshot of the PDF that got attached through the code.
User-added image

I tried 3 diffrtent ways to display the image here as shown in the VF code. But none of them worked. 
Can any body find what Iam doing wrong here.
Best Answer chosen by Das M
Andy BoettcherAndy Boettcher
It all depends on how you're executing this code - if you're doing it all at once, you may be running into order of execution/transaction commit issues.

Can you try seperating the processes out?  Save the attachment, then have that launch a new VF page that fires the email template?

All Answers

Andy BoettcherAndy Boettcher
Does it work if you remove the "renderas=pdf" from the apex:page tag?
Das MDas M
No.
If I open this VF Page direcltly in URL lke (https://c.cs41.visual.force.com/apex/InventoryPDF?id=00155000006SlRy&fileId=00P55000000HHz1

It works fine. It renders the signature image as expected.
Andy BoettcherAndy Boettcher
If you set the "renderas=pdf" in the apex:page tag of your "InventoryPDF" VF page - does the image render?

Otherwise I don't understand your question.
Das MDas M
Not in the Attachment. It shows as hown in the screeshot.  But if I copy paste the VF page URL in browser it renders correclty. So I am not sure it's gettting lost in the Attachment crearion step.
Das MDas M
My prblem is In that attachment the image is not showing.
Andy BoettcherAndy Boettcher
It all depends on how you're executing this code - if you're doing it all at once, you may be running into order of execution/transaction commit issues.

Can you try seperating the processes out?  Save the attachment, then have that launch a new VF page that fires the email template?
This was selected as the best answer
Das MDas M
OK. I can try that. I tried with adding delay between these actions but that didn't work.
Gyanender SinghGyanender Singh
Hi Das,

In place of the static resource , please save the image in the document folder and check the check box for externally use image and after that use that image in the vf page it will see correctly.

Thanks
Gyani.
Das MDas M
Andy- Seprating the process fixed the isse. Thank You.
Gyani- Thanks for your input. I was not using Static Resources. I am using the staradard attachments.