Apache FOP 1.1 QRCodes with zxing

2019-05-11 19:40发布

问题:

OK I am having an issue producing QR Codes in FOP 1.1 using barcode4j-2.1 and zxing-0.1.2. I currently have a FOP 1.0 implementation working correctly, by adding <prefer-renderer>true</prefer-renderer> to the fop configuration file.

barcode4j barcodes are working regardless if prefer renderer is set or not, fixed in barcode4j-2.1.

I have all necessary dependancies:

  • fop-zxing-0.1.2-jar-with-dependencies.jar
  • barcode4j-fop-ext-complete.jar
  • saxon9he.jar - using for xslt 2.0 ...

here is the barcode snippet:

<fo:block>
  <fo:instream-foreign-object>
    <qr:qr-code xmlns:qr="http://hobbut.ru/fop/qr-code/"
                   width="5cm"
         message="TEST DATA"
              correction="m"
            encoding="UTF-8">
    </qr:qr-code>
  </fo:instream-foreign-object>
</fo:block>

When trying to convert prefer-renderer seems to have no effect, I am receiving the error:

SEVERE: Image not available. URI: (instream-object). Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for null (No context info available)
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for null
    at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:180)
    at org.apache.fop.render.intermediate.AbstractIFPainter.drawImageUsingDocument(AbstractIFPainter.java:296)
    at org.apache.fop.render.pdf.PDFPainter.drawImage(PDFPainter.java:203)
    at org.apache.fop.render.intermediate.IFRenderer.renderForeignObject(IFRenderer.java:1290)
    at org.apache.fop.render.AbstractRenderer.renderInlineViewport(AbstractRenderer.java:820)
    at org.apache.fop.render.AbstractPathOrientedRenderer.renderInlineViewport(AbstractPathOrientedRenderer.java:785)
    at org.apache.fop.render.intermediate.IFRenderer.renderInlineViewport(IFRenderer.java:866)
    at org.apache.fop.render.AbstractRenderer.renderInlineArea(AbstractRenderer.java:678)
    at org.apache.fop.render.intermediate.IFRenderer.renderInlineArea(IFRenderer.java:913)
    at org.apache.fop.render.AbstractRenderer.renderLineArea(AbstractRenderer.java:643)
    at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:561)
    at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:598)
    at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:980)
    at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:546)
    at org.apache.fop.render.AbstractRenderer.renderFlow(AbstractRenderer.java:451)
    at org.apache.fop.render.AbstractPathOrientedRenderer.renderFlow(AbstractPathOrientedRenderer.java:738)
    at org.apache.fop.render.AbstractRenderer.renderMainReference(AbstractRenderer.java:428)
    at org.apache.fop.render.AbstractRenderer.renderBodyRegion(AbstractRenderer.java:352)
    at org.apache.fop.render.AbstractRenderer.renderRegionViewport(AbstractRenderer.java:299)
    at org.apache.fop.render.intermediate.IFRenderer.renderRegionViewport(IFRenderer.java:748)
    at org.apache.fop.render.AbstractRenderer.renderPageAreas(AbstractRenderer.java:273)
    at org.apache.fop.render.AbstractRenderer.renderPage(AbstractRenderer.java:238)
    at org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:597)
    at org.apache.fop.area.RenderPagesModel.renderPage(RenderPagesModel.java:193)
    at org.apache.fop.area.RenderPagesModel.checkPreparedPages(RenderPagesModel.java:174)
    at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:146)
    at org.apache.fop.layoutmgr.AbstractPageSequenceLayoutManager.finishPage(AbstractPageSequenceLayoutManager.java:312)
    at org.apache.fop.layoutmgr.PageSequenceLayoutManager.finishPage(PageSequenceLayoutManager.java:191)
    at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:115)
    at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:267)
    at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:128)
    at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:347)
    at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:181)
    at net.sf.saxon.event.ContentHandlerProxy.endElement(ContentHandlerProxy.java:395)
    at net.sf.saxon.event.NamespaceReducer.endElement(NamespaceReducer.java:208)
    at net.sf.saxon.event.ComplexContentOutputter.endElement(ComplexContentOutputter.java:459)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:304)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:254)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:615)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:131)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:301)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:254)
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:212)
    at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1034)
    at net.sf.saxon.Controller.transformDocument(Controller.java:1959)
    at net.sf.saxon.Controller.transform(Controller.java:1805)
    at cwc.fop.util.templates.FOPConvert.translate(FOPConvert.java:116)
    at cwc.fop.util.conversion.XML2PDF.translate(XML2PDF.java:151)
    at cwc.fop.util.conversion.XML2PDF.translate(XML2PDF.java:114)
    at cwc.fop.util.conversion.XML2PDF.translate(XML2PDF.java:65)
    at cwc.fop.server.work.WorkerRunnable.run(WorkerRunnable.java:144)
    at cwc.util.threading.WorkQueue$PoolWorker.run(WorkQueue.java:59)

Thanks in advance for any help

回答1:

You're using xmlns:qr="http://hobbut.ru/fop/qr-code/" which has nothing to do with Barcode4J. Seems like you planned to use some other FOP plug-in than Barcode4J but you ultimately placed Barcode4J in the classpath instead of the right plug-in. BTW, Barcode4J has an integration of ZXing for QR Code production in the HEAD branch of its CVS repository.