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}"/>  
        <apex:outputText rendered="{!hasPictureDays}">                
            <div class="headerSlip">{!Opportunity.Account.Name}</div><br/>
            <div class="jobSlip">{!Opportunity.WPA__c}</div>
            <center><svg id="barcode"></svg></center>
    <script type ="text/javascript">
        JsBarcode("#barcode", "{!Opportunity.WPA__c}",{
            fontOptions: "both",
            font :  "OCRB",
            textAlign : "center",
            Textmargin : 5,
            fontSize : 12,
            width: 1,
            height: 50

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[type]/[value].[imagetype]


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

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

There are other barcode generator
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.