JasperReports Ultimate Guide - Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - Barcode4J Sample (version 4.6.0) | |
|
|
|
Main Features in This Sample | |
| Barcodes |
| Barcodes (Barcode4J Custom Component) |
|
|
|||||
top | ||||||
|
||||||
Barcodes | Documented by Sanda Zaharia | |||||
|
||||||
| Description / Goal |
| Shows how to render barcodes in a report, using the barcode components that are shipped with the JasperReports library. | |||
| Since |
| 3.5.2 | |||
| Other Samples |
|
|
|||
|
||||||
|
Barcode Overview
A barcode denotes an encoded graphical representation of data which can be read/decoded using dedicated scanning devices such as barcode scanners. Due to its exceptional ability to completely characterize a given product, the barcode technology became one of the most common product registering technologies. It consists in computing a graphical "fingerprint" for a given object based on a unique digit/character sequence mapped to the object. Once generated, the barcode uniquely identifies the product. When scanned, the barcode allows retrieving the original data it was built on, in order to be visualized or printed out. Barcode Symbologies The whole "fingerprint" graphics is computed from elementary fingerprints of single digits/characters in the sequence. There are several ways to map individual characters or digits to a graphical representation. These mappings are specified in the so-called barcode symbologies. Some very common symbology categories are:
|
|||||
|
||||||
top | ||||||
|
||||||
Barcodes (Barcode4J Custom Component) | Documented by Sanda Zaharia | |||||
|
||||||
| Description / Goal |
| Shows how to render barcodes in a report, using the barcode component based on the Barcode4J library. | |||
| Since |
| 3.5.2 | |||
|
||||||
|
The Barcode4J Library
Today barcodes are present almost everywhere: in wholesales as well as in retails, on the bills, in airports, libraries, banks, hospitals, hotels, theaters, amusement parks, on the internet, and the list could continue... Due to this ubiquity, there is an increasing need of barcode components in the reporting area. Powerful reporting engines should now provide support for as many as possible barcode symbologies. To cover a large category of customer needs, JR comes with 2 built-in barcode components, and in addition, it also makes room for other complementary implementations. This sample illustrates how to use the built-in component based on the open source Barcode4J library. The Barcode4J library supports the following symbologies:
Each of supported symbologies enumerated above is characterized by a specific structure of elements and attributes described in the components.xsd schema. All of them are based on the same Barcode4j parent element, and differences are given by their specific extracontent:
Barcode4j elements is the checksumMode . Allowed values are
auto , ignore , add and check .
Barcode4J Samples Some examples of howto use the available Barcode4j components are given in the JRXML sample:
<componentElement> <reportElement style="Barcode" x="130" y="100" width="200" height="30"/> <c:Code128 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="1.0"> <c:codeExpression><![CDATA["0123456789"]] ></c:codeExpression> </c:Code128> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="135" width="200" height="30"/> <c:Codabar xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="1.2" textPosition="none" wideFactor="4.0"> <c:codeExpression><![CDATA["01234567890"]] ></c:codeExpression> </c:Codabar> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="170" width="70" height="40"/> <c:DataMatrix xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="4.0"> <c:codeExpression><![CDATA["JasperReports"]] ></c:codeExpression> </c:DataMatrix> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="215" width="250" height="30"/> <c:EAN128 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="1.4" checksumMode="check"> <c:codeExpression><![CDATA["0101234567890128"]] ></c:codeExpression> </c:EAN128> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="250" width="400" height="30"/> <c:Code39 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <c:codeExpression><![CDATA["0123456789"]] ></c:codeExpression> </c:Code39> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="285" width="400" height="30"/> <c:USPSIntelligentMail xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" ascenderHeight="8.0" trackHeight="10.0"> <c:codeExpression><![CDATA["00040123456200800001987654321"]] ></c:codeExpression> </c:USPSIntelligentMail> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="320" width="400" height="30"/> <c:RoyalMailCustomer xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" ascenderHeight="8.0" intercharGapWidth="2.5" trackHeight="10.0"> <c:codeExpression><![CDATA["0123456789"]] ></c:codeExpression> </c:RoyalMailCustomer> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="355" width="400" height="30"/> <c:Interleaved2Of5 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <c:codeExpression><![CDATA["0123456789"]] ></c:codeExpression> </c:Interleaved2Of5> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="390" width="400" height="30"/> <c:UPCA xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <c:codeExpression><![CDATA["01234567890"]] ></c:codeExpression> </c:UPCA> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="425" width="400" height="30"/> <c:UPCE xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <c:codeExpression><![CDATA["01234133"]] ></c:codeExpression> </c:UPCE> </componentElement> .... <componentElement> <reportElement style="Barcode" x="130" y="460" width="400" height="30"/> <c:EAN13 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <c:codeExpression><![CDATA["012345678901"]] ></c:codeExpression> </c:EAN13> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="495" width="400" height="30"/> <c:EAN8 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <c:codeExpression><![CDATA["01234565"]] ></c:codeExpression> </c:EAN8> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="530" width="400" height="20"/> <c:POSTNET xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" shortBarHeight="10.0" checksumMode="add"> <c:codeExpression><![CDATA["01234"]] ></c:codeExpression> </c:POSTNET> </componentElement> ... <componentElement> <reportElement style="Barcode" x="130" y="555" width="400" height="30"/> <c:PDF417 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="4.0"> <c:codeExpression><![CDATA["JasperReports"]] ></c:codeExpression> </c:PDF417> </componentElement>Running the Sample Running the sample requires the Apache Ant library. Make sure that ant is already installed on your system (version 1.5 or later).
In a command prompt/terminal window set the current folder to demo/samples/barcode4j within the JasperReports source project and run the > ant test view command.
It will generate all supported document types containing the sample report in the demo/samples/barcode4j/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
|||||
|
|
© 2001- Jaspersoft Corporation www.jaspersoft.com |