+ Start a Discussion
l.trincil.trinci 

Vf page with add image button

There is any way to create a visualforce page that  create a page rendered as a "pdf" that have a button for "insert images"?

 

I need to have an "image" system input on the pdf page (for a manage package) that insert the  "user declared image" on the pdf page..

Like an "insert avatar" botton on the forums

 

 

 

 

 

 

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You would have to insert the images in HTML mode, then switch to PDF mode. PDFs are not interactive (at least, not in the Visualforce sense). Try something like this:

 

public class con {
   public con() {
   }
   public string rendermode { get; set; }
   public void renderpdf() { rendermode = 'pdf'; }
   public string url { get; set; }
}
<apex:page controller="con" renderas="{!rendermode}">
 <apex:form>
  <apex:outputPanel rendered="{!rendermode<>'pdf'}">
   <apex:inputText value="{!url}"/>
   <apex:commandButton value="Render PDF" action="{!renderpdf}"/>
  </apex:outputPanel>
  <apex:outputPanel rendered="{!rendermode='pdf'}">
   <apex:image url="{!url}"/>
  </apex:outputPanel>
 </apex:form>
</apex:page>

You can also use multiple pages (e.g. page1 and page2), one of which collects settings, and the second one renders the PDF. Of course, if you want to render the image as a user-selected image instead of a URL, you'll have to actually save the file to the server somewhere (as a document, for example), then serve up the document in the PDF controller.