barcode.fo Example Errors in FOP

Q

What are those errors when using "barcode.fo" example in FOP to generated a PDF file?

✍: FYIcenter.com

A

FOP 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.x\fop

fyicenter> 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:

fyicenter> fop -c examples\fo\advanced\bar.conf.xml 
   examples\fo\advanced\barcode.fo \temp\carcode.pdf
...
java.lang.RuntimeException: java.io.FileNotFoundException: 
\local\fop-2.x\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, \local\fop-2.x\examples\fo\advanced\examples\fo\advanced\K3.xml, is wrong. We need to modify the FOP configuration file and try it again:

fyicenter> copy examples\fo\advanced\bar.conf.xml 
   examples\fo\advanced\bar-original.conf.xml

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

fyicenter> 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.

 

⇒ Generate K3.xml Metrics File in FOP

⇐ Run simplecol.fo Example in FOP

⇑ FOP Commands and Examples

⇑⇑ FAQ for FOP (Formatting Object Processor)

2016-07-02, ∼4869🔥, 0💬