Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding barcodes using Apache Fop in Java

I'm using Apache Fop to generate a pdf document that includes a PDF417 barcode, and when i use the command line it works:

fop -fo source.fo -pdf result.pdf

But when I use the Java alternative, the barcode appears blank and the log show these warnings:

Unknown formatting object "{http://barcode4j.krysalis.org/ns}barcode" encountered (a child of fo:instream-foreign-object}. (See position 88:1266)
Unknown formatting object "{http://barcode4j.krysalis.org/ns}pdf417" encountered (a child of barcode}. (See position 89:45)

I've included these dependencies in Maven:

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>fop</artifactId>
    <version>2.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.sf.barcode4j/barcode4j -->
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j</artifactId>
    <version>2.1</version>
</dependency>

What I'm missing?

Thanks in advance!

like image 662
Julio Villane Avatar asked Jun 20 '26 15:06

Julio Villane


1 Answers

The answer was very simple, instead of using the maven dependecy:

<!-- https://mvnrepository.com/artifact/net.sf.barcode4j/barcode4j -->
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j</artifactId>
    <version>2.1</version>
</dependency>

I needed to use:

<!-- https://mvnrepository.com/artifact/net.sf.barcode4j/barcode4j-fop-ext -->
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j-fop-ext</artifactId>
    <version>2.1</version>
</dependency>

Pretty obvious now. Thanks to myself! :)

like image 114
Julio Villane Avatar answered Jun 22 '26 04:06

Julio Villane