J4L Barcodes plugin for Apache FOP (generation of PDF files)

Copyright J4L Components (http://www.java4less.com) 2008.

 

Introduction

Apache FOP is an implementation of the XSL formatting objects (XSL-FO) which takes an input XML file and creates PDF files. It can also create other output formats but the most popular is PDF.

The J4L Barcode plugin for Apache FOP allows you to add barcodes to the Apache FOP documents. This allows you to create PDF files which contain the following types of barcodes:

The plugin not a standalone product but isincluded in the regular J4L Barcoding components license, if you need general information about the barcode itself (meaning of format , encoding ...) please refer to the documentation of the barcoding components.

Installation

In order to use the plugin in your FOP documents you need to add the following jars to your classpath:

Sample application

We deliver a simple application which creates PDF files using as input a FOP file:

How to run the sample application:

  1. Create a Java Project with your favorite IDE tool (Eclipse, Netbeans ...)
  2. Add ExampleFO2PDF.java to your project
  3. Add rbarcode-fop.jar, lib/rbarcode.jar and lib/qrcode.jar to the project´s classpath
  4. Download Apache FOP (we tested 0.93 and 0.95) and add all fop jar files to your classpath
  5. Set the working directory of your project to be the examples subdiretory (so that the *.fo files can be read by the application)
  6. Run the application, it will create a set of pdf files in the working directory

 

How to add barcode to a FOP / PDF file

If you are not familiar with FOP, please read this tutorial first. If you are familiar with FOP, you know FOP files are XML files which describe the content of the target PDF file. In order to add a barcode to a FOP file you use these element:

 

<fo:instream-foreign-object >

<j4lbarcode xmlns="http://java4less.com/j4lbarcode/fop" mode="inline">

<barcode1d>

<value>This is a code128</value>
<type>CODE128</type>
<set>A</set>
<X>1</X>
<margin>30</margin>
<text>Readable text</text>
<barHeight>40</barHeight>
<leftMargin>40</leftMargin>
<topMargin>50</topMargin>
<barColor>BLUE</barColor>
<backColor>YELLOW</backColor>
<fontColor>RED</fontColor>

</barcode1d>

</j4lbarcode>

</fo:instream-foreign-object>

The blue elements are always the same for any type of barcode, the green elements will change depending on the kind of barcode you want to create (barcode 1D, pdf417 , datamatrix or qrcode). The example above creates a Barcode 1D.

For Datamatrix you would use:

<fo:instream-foreign-object >
<j4lbarcode xmlns="http://java4less.com/j4lbarcode/fop" mode="inline">

<datamatrix>

<code>This is a Datamatrix</code>
<moduleSize>2</moduleSize>
<processTilde>false</processTilde>
<margin>30</margin>
<encoding>AUTO</encoding>
<format>C24X24</format>

</datamatrix>

</j4lbarcode>
</fo:instream-foreign-object>

 

For PDF417:

<fo:instream-foreign-object >
<j4lbarcode xmlns="http://java4less.com/j4lbarcode/fop" mode="inline">

<pdf417>

<code>This is a PDF417</code>
<rows>0</rows>
<maxRows>30</maxRows>
<cols>5</cols>
<ecLevel>3</ecLevel>
<compaction>TEXT</compaction>
<X>1</X>
<H>10</H>
<margin>30</margin>

</pdf417>

</j4lbarcode>
</fo:instream-foreign-object>

and for QRCode:

 

<fo:instream-foreign-object >
<j4lbarcode xmlns="http://java4less.com/j4lbarcode/fop" mode="inline">

<qrcode>

<code>This is a QRCode</code>
<moduleSize>2</moduleSize>
<processTilde>false</processTilde>
<margin>30</margin>
<ecLevel>H</ecLevel>
<encoding>AUTO</encoding>
<configuration>1</configuration>

</qrcode>

</j4lbarcode>
</fo:instream-foreign-object>

 

This section provides now a short description of the meaning of the elements that define the barcode:

Getting help

Send an email to java4lessATconfluencia.net if you have questions.