Embedded FOP 2.3 - SVG not working when transforming from any source but files

classic Classic list List threaded Threaded
1 message Options
TDK
Reply | Threaded
Open this post in threaded view
|

Embedded FOP 2.3 - SVG not working when transforming from any source but files

TDK
Hi,

I experienced a weird behaviour when embedding SVG and transform it with FOP 2.3 when using another input source than files

The part that deals with the transformation look like this:

One time init:
kTransFactory = new net.sf.saxon.TransformerFactoryImpl();
kFopFactory = FopFactory.newInstance(new File(kConfigPath));


Transformation:
Transformer transformer = kTransFactory.newTransformer(xslt);
                        transformer.setErrorListener(errorListener);
FOUserAgent foUserAgent = kFopFactory.newFOUserAgent();
Fop fop = kFopFactory.newFop(type, foUserAgent, result);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(xml, res);

xslt and xml are StreamSource objects.

If I get the data from a file there is no problem embedding svg images in
the pdf.
I.e.
StreamSource xslt = new StreamSource(new File("path to file"));
StreamSource xml = new StreamSource(new File("path to file"));
produces the correct output and embeds the SVG image correctly into the
pdf/ps.

On the other hand, if I get the data via a socket and use byte[] as input,
like so:
StreamSource xslt = new StreamSource(new ByteArrayInputStream(xsltData));
StreamSource xml = new StreamSource(new ByteArrayInputStream(xmlData));

I get no SVG images in the pdf/ps output.
Log output with stacktrace when generating pdf/ps:

SVG graphic could not be built. Reason: org.apache.batik.bridge.BridgeException: file:/../../../workspace/project01/data/fop2/:-1
The attribute "d" of the element <path> is invalid
org.apache.batik.bridge.BridgeException: file:/../../../workspace/project01/data/fop2/:-1
The attribute "d" of the element <path> is invalid
        at org.apache.batik.bridge.SVGPathElementBridge.buildShape(SVGPathElementBridge.java:94)
        at org.apache.batik.bridge.SVGShapeElementBridge.createGraphicsNode(SVGShapeElementBridge.java:60)
        at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:213)
        at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
        at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:82)
        at org.apache.fop.render.ps.PSImageHandlerSVG.handleImage(PSImageHandlerSVG.java:127)
        at org.apache.fop.render.intermediate.AbstractIFPainter.drawImage(AbstractIFPainter.java:249)
        at org.apache.fop.render.intermediate.AbstractIFPainter.drawImage(AbstractIFPainter.java:205)
        at org.apache.fop.render.intermediate.AbstractIFPainter.drawImageUsingImageHandler(AbstractIFPainter.java:170)
        at org.apache.fop.render.ps.PSPainter.drawImageUsingImageHandler(PSPainter.java:161)
        at org.apache.fop.render.intermediate.AbstractIFPainter.drawImageUsingDocument(AbstractIFPainter.java:319)
        at org.apache.fop.render.ps.PSPainter.drawImage(PSPainter.java:189)
        at org.apache.fop.render.intermediate.IFRenderer.renderForeignObject(IFRenderer.java:1312)
        at org.apache.fop.render.AbstractRenderer.renderInlineViewport(AbstractRenderer.java:864)
        at org.apache.fop.render.AbstractPathOrientedRenderer.renderInlineViewport(AbstractPathOrientedRenderer.java:831)
        at org.apache.fop.render.intermediate.IFRenderer.renderInlineViewport(IFRenderer.java:862)
        at org.apache.fop.render.AbstractRenderer.renderInlineArea(AbstractRenderer.java:717)
        at org.apache.fop.render.intermediate.IFRenderer.renderInlineArea(IFRenderer.java:926)
        at org.apache.fop.render.AbstractRenderer.renderLineArea(AbstractRenderer.java:692)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:573)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:615)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractPathOrientedRenderer.renderReferenceArea(AbstractPathOrientedRenderer.java:756)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:601)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:615)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:615)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractPathOrientedRenderer.renderReferenceArea(AbstractPathOrientedRenderer.java:756)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:601)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:615)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractPathOrientedRenderer.renderReferenceArea(AbstractPathOrientedRenderer.java:756)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:601)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlockViewport(IFRenderer.java:811)
        at org.apache.fop.render.AbstractRenderer.renderBlock(AbstractRenderer.java:594)
        at org.apache.fop.render.intermediate.IFRenderer.renderBlock(IFRenderer.java:998)
        at org.apache.fop.render.AbstractRenderer.renderBlocks(AbstractRenderer.java:558)
        at org.apache.fop.render.AbstractRenderer.renderFlow(AbstractRenderer.java:459)
        at org.apache.fop.render.AbstractPathOrientedRenderer.renderFlow(AbstractPathOrientedRenderer.java:784)
        at org.apache.fop.render.AbstractRenderer.renderMainReference(AbstractRenderer.java:436)
        at org.apache.fop.render.AbstractRenderer.renderBodyRegion(AbstractRenderer.java:360)
        at org.apache.fop.render.AbstractRenderer.renderRegionViewport(AbstractRenderer.java:307)
        at org.apache.fop.render.intermediate.IFRenderer.renderRegionViewport(IFRenderer.java:737)
        at org.apache.fop.render.AbstractRenderer.renderPageAreas(AbstractRenderer.java:272)
        at org.apache.fop.render.AbstractRenderer.renderPage(AbstractRenderer.java:245)
        at org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:587)
        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:316)
        at org.apache.fop.layoutmgr.PageSequenceLayoutManager.finishPage(PageSequenceLayoutManager.java:243)
        at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:147)
        at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:267)
        at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:130)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:360)
        at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:190)
        at net.sf.saxon.event.ContentHandlerProxy.endElement(ContentHandlerProxy.java:414)
        at net.sf.saxon.event.NamespaceReducer.endElement(NamespaceReducer.java:228)
        at net.sf.saxon.event.ComplexContentOutputter.endElement(ComplexContentOutputter.java:578)
        at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:340)
        at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:284)
        at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687)
        at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:151)
        at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:337)
        at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:284)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:347)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:505)
        at net.sf.saxon.Controller.transformDocument(Controller.java:2411)
        at net.sf.saxon.Controller.transform(Controller.java:1979)
        at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
        at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
        at FopTransformer.transform(FopTransformer.java:441)
        at FopTransformer.transform(FopTransformer.java:226)
        at Worker.processFOPTransform(Worker.java:235)
        at Worker.processFOPRequest(Worker.java:150)
        at Worker.run(Worker.java:61)
        at java.lang.Thread.run(Thread.java:748)

Following svg in the fo: (a barcode generated with the RenderX xsl template)
<fo:block padding="0.1mm" margin="0mm" keep-together.within-line="always" text-align="center">
    <fo:instream-foreign-object content-height="100%" content-width="100%">
        <svg:svg viewBox="0 0 16240 1800" height="5mm" width="45.111111111111114mm">
            <desc>
                <barcode value="S190001" type="code128" makeUCC="false"/>
            </desc>
            <svg:path fill="black" d="M 0 0 l 0 1800 290 0 0 -1800 z m 290 0 m 145 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 145 0 0 -1800 z m 145 0 m 580 0 l 0 1800 290 0 0 -1800 z m 290 0 m 145 0 l 0 1800 435 0 0 -1800 z m 435 0 m 145 0 l 0 1800 145 0 0 -1800 z m 145 0 m 435 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 435 0 0 -1800 z m 435 0 m 290 0 l 0 1800 290 0 0 -1800 z m 290 0 m 145 0 l 0 1800 435 0 0 -1800 z m 435 0 m 290 0 l 0 1800 145 0 0 -1800 z m 145 0 m 145 0 l 0 1800 290 0 0 -1800 z m 290 0 m 290 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 435 0 0 -1800 z m 435 0 m 145 0 l 0 1800 290 0 0 -1800 z m 290 0 m 290 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 435 0 0 -1800 z m 435 0 m 145 0 l 0 1800 290 0 0 -1800 z m 290 0 m 290 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 435 0 0 -1800 z m 435 0 m 145 0 l 0 1800 290 0 0 -1800 z m 290 0 m 290 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 435 0 0 -1800 z m 435 0 m 290 0 l 0 1800 290 0 0 -1800 z m 290 0 m 145 0 l 0 1800 145 0 0 -1800 z m 145 0 m 435 0 l 0 1800 145 0 0 -1800 z m 145 0 m 290 0 l 0 1800 290 0 0 -1800 z m 290 0 m 290 0 l 0 1800 290 0 0 -1800 z m 290 0 m 435 0 l 0 1800 435 0 0 -1800 z m 435 0 m 145 0 l 0 1800 145 0 0 -1800 z m 145 0 m 145 0 l 0 1800 290 0 0 -1800 z m 290 0"/>
        </svg:svg>
    </fo:instream-foreign-object>
</fo:block>

The PDF will still get generated, but all svg-images are missing.

Is there anything I do wrong? (The apache-fop homepage mentions using a ByteArrayInputStream, however converting the byte[] to a String and using a StreamReader I get the exact same result.. no SVG in PDF/PS)
I would really like to avoid saving the received byte[] data into a file to get a correct output from FOP/Batik

Thanks!
Philipp





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]