In Salesforce: I have printed a Barcode using the SVG tag in the Visualforce Page. But, when the Visualforce Page is rendered as a pdf using the 'renderAs' attribute of the component, the Barcode doesn't show up!
<apex:page renderAs="pdf" sidebar="false" showHeader="false" applyBodyTag="false">
<head>
<script src="http://cdn.jsdelivr.net/jsbarcode/3.6.0/JsBarcode.all.min.js"></script>
<script></script>
</head>
<body>
<svg id="barcodesvg" >Hello World!</svg> <!-- style="width:80px; height:25px;" -->
</body>
<script>
JsBarcode("#barcodesvg", "Hey World!");
console.log(JsBarcode("#barcodesvg", "Hey World!"));
</script>
</apex:page>
Been a week working over it. Any help would be greatly appreciated!
Visualforce's render to PDF uses (or at least used to) Java library called Flying Saucer. There's no browser as such, no JavaScript engine to run your code.
You'd have to generate the barcode different way. Look for JavaScript libraries able to prerender your image & save it as PNG attachment for example, then use it in VF. Or if it's a relatively simple barcode you could maybe do the calculations in Apex and display it in pure html as series of black & white <span>
s (should be easy to find sample implementations for Java or .NET that have syntax not too different from Apex... or even use that JavaScript's source code as inspiration). Or maybe call another server that can generate images, maybe put your own instance of https://github.com/zxing/zxing somewhere (Heroku?) and call that for images.
If you can live without the real Visualforce renderAs="pdf" (forget about using this in email templates, atatchments, any kind of server code that for example generates file in SF and uploads somewhere) then it can stay JavaScript. Instruct users how to print the page to PDF or maybe you'll have luck with https://github.com/MrRio/jsPDF