Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating barcodes within a template for use with Apache FOP

I am working on a project that generates invoices in PDF format from xml data output by another piece of software, and one of the requirements of these invoices is to create barcodes for some of the node data and place them in the form. Ideally, the barcodes would be generated from inside the template, rather than calling another program to generate them and then have the template try to find them as PNGs or some other image format.

I've tried using the barcode4j extension, but with no results.

<?xml version="1.0" encoding="UTF-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"  xmlns:barcode="http://barcode4j.krysalis.org/ns" font-size="10pt">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="master0" page-width="21.0cm" page-height="29.7cm" margin-top="0.0cm" margin-bottom="0.5cm" margin-left="0.5cm" margin-right="0.25cm">
      <fo:region-body region-name="body0" margin-top="0.5cm" margin-bottom="0.5cm"/>
      <fo:region-before region-name="header0" extent="1.5cm"/>
      <fo:region-after region-name="footer0" extent="1.89cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="master0">
    <fo:flow flow-name="body0">
    <xsl:variable name="CheckMaster" select="count(master_bill_of_lading/details/orders/order)"/>
    <xsl:variable name="country" select="master_bill_of_lading/header/Country"/>

  <xsl:variable name="barcode-cfg">
        <barcode>
            <code39>
                <height>16mm</height>
                <module-width>0.3mm</module-width>
                <human-readable>
                    <placement>none</placement>
                </human-readable>
            </code39>
        </barcode>
        </xsl:variable>

   <fo:block>

 <fo:instream-foreign-object>
<xsl:variable name="bc" select="barcode:generate($barcode-cfg, 123456)" />
   <xsl:copy-of select="$bc" />
 </fo:instream-foreign-object>

...

Aside from having tried this, any solution that allows me to generate the bar codes within the template would be hugely appreciated, as it is extremely difficult to find consistent on-line references to alleged solutions.

Edit: I was able to solve this problem using the FOP extension barcode4j, which only requires you to add the included jars to the path and lib folder inside FOP then create a bar code using inside an fo:instream-foreign-object block

like image 504
adam5990 Avatar asked Aug 14 '13 19:08

adam5990


Video Answer


1 Answers

Most of the 1d barcodes are supported by RenderX's freely available XSL style sheets that process a barcode on the fly in XSL to SVG. See RenderX Barcode XSLs. This includes 3of9 barcodes that your example shows.

like image 59
Kevin Brown Avatar answered Sep 17 '22 11:09

Kevin Brown