barcode.fo Example Errors in fop-2.0-bin.zip

Q

What are those errors when using "barcode.fo" example in fop-2.0-bin.zip to generated a PDF file?

✍: FYIcenter.com

A

fop-2.0-bin.zip comes with an example XSL-FO file, barcode.fo, which shows how to generate barcodes in PDF. But it has a number errors, if you use the "fop" command to convert it into a PDF file:

\fyicenter>cd \local\fop-2.0

\local\fop-2.0>echo %java_home%
   \Program Files\Java\jdk1.8.0_45\

\local\fop-2.0>fop examples\fo\advanced\barcode.fo \temp\barcode.pdf
...
... org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Barcode,normal,400" not found. Substituting with 
"any,normal,400".
...

This is not really a warning. It is an error. FOP could not find the "Barcode" font. We need to provide the FOP configuration file that specify where the font file is:

\local\fop-2.0>fop -c examples\fo\advanced\bar.conf.xml 
   examples\fo\advanced\barcode.fo \temp\carcode.pdf
...
java.lang.RuntimeException: java.io.FileNotFoundException: 
C:\local\fop-2.0\examples\fo\advanced\examples\fo\advanced\K3.xml 
(The system cannot find the path specified)
  at org.apache.fop.fonts.LazyFont.load(LazyFont.java:130)
  at org.apache.fop.fonts.LazyFont.getAscender(LazyFont.java:233)
  at org.apache.fop.fonts.Font.getAscender(Font.java:118)
  at org.apache.fop.layoutmgr.BlockLayoutManager.initialize
     (BlockLayoutManager.java:82)
  at org.apache.fop.layoutmgr.AbstractLayoutManager.getChildLM
     (AbstractLayoutManager.java:118)
  at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements
     (FlowLayoutManager.java:128)
  at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements
     (FlowLayoutManager.java:69)
  at org.apache.fop.layoutmgr.PageBreaker.getNextKnuthElements
     (PageBreaker.java:252)
  at org.apache.fop.layoutmgr.AbstractBreaker.getNextBlockList
     (AbstractBreaker.java:643)
  at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList
     (PageBreaker.java:178)
  at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList
     (PageBreaker.java:158)
  at org.apache.fop.layoutmgr.AbstractBreaker.doLayout
     (AbstractBreaker.java:384)
  at org.apache.fop.layoutmgr.PageBreaker.doLayout(PageBreaker.java:112)
...

Now the path name of metrics file, C:\local\fop-2.0\examples\fo\advanced\examples\fo\advanced\K3.xml, is wrong. We need to modify the FOP configuration file and try it again:

\local\fop-2.0>copy examples\fo\advanced\bar.conf.xml 
   examples\fo\advanced\bar-original.conf.xml

\local\fop-2.0>edit examples\fo\advanced\bar.conf.xml 
...
      <fonts>
        <font metrics-url="K3.xml" kerning="no" embed-url="K3.ttf">
...

\local\fop-2.0>fop -c examples\fo\advanced\bar.conf.xml 
   examples\fo\advanced\barcode.fo \temp\carcode.pdf
...
java.lang.RuntimeException: org.apache.fop.apps.FOPException: 
Missing metrics-version attribute - please regenerate the font 
metrics file with a more recent version of FOP.
org.xml.sax.SAXException: Missing metrics-version attribute - 
please regenerate the font metrics file with a more recent 
version of FOP.
  at org.apache.fop.fonts.LazyFont.load(LazyFont.java:125)
  at org.apache.fop.fonts.LazyFont.getAscender(LazyFont.java:233)
  at org.apache.fop.fonts.Font.getAscender(Font.java:118)
  at org.apache.fop.layoutmgr.BlockLayoutManager.initialize
     (BlockLayoutManager.java:82)
  at org.apache.fop.layoutmgr.AbstractLayoutManager.getChildLM
     (AbstractLayoutManager.java:118)
  at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements
     (FlowLayoutManager.java:128)
  at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements
     (FlowLayoutManager.java:69)
...        

The metrics file located properly now. But it is outdated. See the next tutorial on how to regenerate the metrics file.

Back to FAQ on FOP (Formatting Objects Processor).

2016-07-02, 1032👍, 0💬