jsreport

jsreport template dynamic generate 2D Barcode


I am a new user for JSReport, I want to build a template for phantomjs PDF that include a 2D Barcode, however, 2D Barcode content generate dynamically. Could anyone can guild? Thanks for helping.


Solution

  • This depends how you want to generate the barcode image. One option is to use external (free) service which does this for you, then you just need to insert html image with proper url

    <img src='https://www.barcodesinc.com/generator/image.php?code=ABCDEFG&style=197&type=C128B&width=180&height=50&xres=1&font=3'/>
    

    You would typically fill the code using handlebars in jsreport like this

    <img src='https://www.barcodesinc.com/generator/image.php?code={{code}}&style=197&type=C128B&width=180&height=50&xres=1&font=3'/>
    

    Playground demo
    https://playground.jsreport.net/w/anon/FnOXpvbt

    Another option is using an npm module that can render the barcodes serverside like the bwip-js.

    Playground demo
    https://playground.jsreport.net/w/anon/EYFN1vXc