2008-08-30

Barcode4J

I just threw Barcode4J's library files into Novelang and in the next version you'll be able to include various kinds of beautiful barcodes in your PDFs. I could say: "look how powerful I am!" but as a fervent Novelang blogreader you know now who's deserving the fame. PDF-embedded barcodes in a FO stylesheet requires such a namespace declaration:
<xsl:stylesheet version="1.0"
  ...
  xmlns:barcode="http://barcode4j.krysalis.org/ns"
>
And the barcode itself looks like this:
  <fo:block>
    <fo:instream-foreign-object>
      <barcode:barcode message="L loves L!">
        <barcode:datamatrix>
        <barcode:module-width>9.5mm</barcode:module-width>
        <barcode:shape>force-square</barcode:shape>
        </barcode:datamatrix>
      </barcode:barcode>
    </fo:instream-foreign-object>
  </fo:block>
Of course the "L loves L!" message could be replaced by something more serious like an EAN-13 barcode (the one used for ISBNs). In this case the <barcode:datamatrix> element becomes <barcode:ean-13> but you get the idea (datamatrix looks very pretty). Barcode4J's documentation is excellent so at best I would do some copy-paste. Just one advice of mine: in order to avoid FOP warnings you should add the barcode: namespace in front of each element. Regarding Novelang's develepment roadmap, this barcode feature may look a bit alien but I was in need for it and it doesn't cripple Novelang architecture or grammar at all, just a few more files in the lib/ directory. The only problem I ran through was a missing SVG-related classes that appeared to be in the xml-apis-ext.jar file in Batik-1.7 that I renamed into batik-xml-apis-ext-1.7.jar. It's ok now and I won't complain if projects like FOP or Batik come with many jar files that help to understand what's doing what. Barcode4J is definitely sweet and makes your project shine. Long live to its developers.

No comments: