function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Afzaal HassanAfzaal Hassan 

Render a Javascript generated barcode as pdf

I am using a JS library called barcode39 to create a barcode image. I already imported the JS library in the static resource and have included the JS in my visualforce page. The barcode is generating fine in the VF page. The problem is I need to render this page as a pdf. When I do that, the barcode image does not appear. I DO NOT want to use the image url from barcodeinc because its very unstable. Can you please let me know what I can do to modify the code below to make the barcode render in pdf as well? Thank you

<apex:page standardController="Opportunity" extensions="LPP_PackingSlip" showHeader="false" sidebar="false" renderAs="pdf" standardStylesheets="false" applyHtmlTag="false">  
 <apex:includeScript value="{!$Resource.BarcodeScript}"/>  
    <head>  
<body>          
    
        <apex:outputText rendered="{!hasPictureDays}">                
           
            <!--Header-->
            <br/>
            <div class="headerSlip">{!Opportunity.Account.Name}</div><br/>
            <div class="jobSlip">{!Opportunity.WPA__c}</div>
            <center><svg id="barcode"></svg></center>
            <br/><br/>  
</apex:outputText>    
    </body>
        
    
    <script type ="text/javascript">
        JsBarcode("#barcode", "{!Opportunity.WPA__c}",{
            fontOptions: "both",
            font :  "OCRB",
            textAlign : "center",
            Textmargin : 5,
            fontSize : 12,
            width: 1,
            height: 50
 
 });
 

  
  </script>
    
</apex:page>
Dushyant SonwarDushyant Sonwar
Hi Afzal,

Your js library approach will not work in pdf as javascript does not work in pdf engine.


You can use the image generation technique using barcode4me
http://barcodes4.me/barcode/[type]/[value].[imagetype]


example
http://www.barcodes4.me/barcode/c39/AnyValueYouWish.png

You can also read it more about it on this API documentation website.

http://barcodes4.me/apidocumentation


Hope this helps.
 
Dushyant SonwarDushyant Sonwar
You can also give this api a shot

There are other barcode generator
example 

https://generator.barcodetools.com/


https://generator.barcodetools.com/barcode.png?gen=0&data=1234567&bcolor=FFFFFF&fcolor=000000&tcolor=000000&fh=14&bred=0&w2n=2.5&xdim=2&w=&h=120&debug=1&btype=7&angle=0&quiet=1&balign=2&talign=0&guarg=1&text=1&tdown=1&stst=1&schk=0&cchk=1&ntxt=1&c128=0
Afzaal HassanAfzaal Hassan
@dushyant sonwar. Thank you for the reply. Is there no way to use the barcode39 library instead of calling out these external urls? 
Afzaal HassanAfzaal Hassan
@dushyant the JS i snot executing when rendered as Pdf
Dushyant SonwarDushyant Sonwar
Afzal , as i said previously , the js library will not work in case of PDF generation.

You need to use image generation technique if you want to use barcode as PDF.

Thanks,