+ Start a Discussion
dstrickrottdstrickrott 

How to display barcode in visualforce page for a pdf

I have a Visualforce page that prints in pdf format.  I want the barcode, which is generated by a third party site, to display in the pdf when I print it.  How can I do this? 

I have two fields in my Salesforce custom object page - one named Barcode__c for a string and one named Barcode_View__c with a formula as follows (which works fine):
IMAGE("//www.barcodesinc.com/generator/image.php?code="&Barcode__c&"&style=325&type=C128B&width=200&height=50&xres=1&font=3",Barcode__c)

In my Visualforce page, I've tried the following four codes, all of which display either a URL or a broken link, but not the barcode itself.  How do I get the barcode to appear in the pdf?
  
 1) This displays the URL  <apex:outputText value="{!RMAShpipmentHeader.Barcode_View__c}"> </apex:outputText>

 2) This displays a broken link <apex:image value="{!URLFOR('http://www.barcodesinc.com/generator/image.php',null,[code='{!RMAShpipmentHeader.Barcode__c}', style=325,type='C128B', width=200, height=50, xres=1, font=3])}" />   
   
3) This displays a broken link  <apex:image value="http://www.barcodesinc.com/generator/image.php?code={!RMAShpipmentHeader.Barcode__c}%26style=325%26‌​type=C128B%26width=200‌​%26height=50%26xres=1%26fo‌​nt=3" />
   
 4) This displays the URL  IMAGE("//www.barcodesinc.com/generator/image.php?code={!RMAShpipmentHeader.Barcode__c}"&"&style=325&type=C128B&width=200&height=50&xres=1&font=3","{!RMAShpipmentHeader.Barcode__c}")

Thanks,
Dawn
SalesFORCE_enFORCErSalesFORCE_enFORCEr
What happens when you use this:
 <apex:outputField value="{!RMAShpipmentHeader.Barcode_View__c}"> </apex:outputField>
dstrickrottdstrickrott
When I use this
 <apex:outputField value="{!RMAShpipmentHeader.Barcode_View__c}"> </apex:outputField>
 
I see this on the pdf:
 
<img
src="//www.barcodesinc.com/generator/image.php?code=123456_24009876&amp;style=325&amp;type=C128B&amp;width=200&amp;height=50&alt="123456_24009876" border="0"/>
dstrickrottdstrickrott
Whoops, sorry.  When I use this

 <apex:outputField value="{!RMAShpipmentHeader.Barcode_View__c}"> </apex:outputField>
 
I see this a broken link on the pdf.
venkat,pattapuvenkat,pattapu
Hi dstrickrott ,

After doing a long research about 2 days, I finally find a solution for your problem as well as my problem...

Directly using apex tag outputtext has no use

so create a controller like below :

 
public with sharing class Pdfimage{   
public List<Payment__C> Paylist {get; set;}
      public String imageUrl{get;set;} //CH07
  
       public Pdfimage(){
        Paylist = [SELECT Id, Name  FROM Payment__C
                        WHERE Id =: Apexpages.currentPage().getParameters().get('Id')];
                       
      imageUrl='https://www.barcodesinc.com/generator/image.php?code='+Paylist .get(0).name+'&style=325&type=C128B&width=200&height=50&xres=1&font=3';
     
      }
        
}
 In visualforce page add like below :
<apex:page showHeader="false" sidebar="false" controller="Pdfimage" cache="false" standardstylesheets="false" renderAs="pdf" applyHtmlTag="false">
    <html>
         <table>
                <tr>
                  <td colspan="8">         
                    <apex:image value="{!imageUrl}"/>
                  </td>
                </tr>
          </table>
      </html>
</apex:page>



Last step Enter Given URL In Remote site settings https://www.barcodesinc.com

If you find helpful Please Hit a like and give the best Answer, close the above thread...


Thanks ,
Venkat Pattapu

 
Sudheera LakmalSudheera Lakmal
Hi Venkat,
Your solution works for me after struggling with various solutions for few days. Thanks for saving my day..!