Ask Reuben
GRW Fallback Image
Why does Genero Report Writer error if an image file cannot be found?
How can I ignore the error if an image cannot be found?
How can I specify a fallback image if an image cannot be found?
The default behaviour of Genero Report Writer when it cannot find an Image is to stop with an error. There is a very good reason for this, if you are sending out documents with your company logo on them, if for some reason something happens to that company logo file, you do not want to send documents output with a blank space or placeholder image where that logo should be.
When an image cannot be found, the error message may vary due to the type of image and the format of the report. One such error has the number 31370. If you want to see such an error, you can easily modify OrderReport from the Tutorials & Samples – Reports demo. Find OrderReport.4rp, click on the ImageBox in the top left corner of the report and change the Location value from “…genero-files/samples/Reports/OrderReport/images/office_logo_new.svg” to “…genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg”. If you do this you may see output of
Premature end of file Cause:/Users/reubenbarclay/genero-files/samples/Reports/OrderReport/OrderReport.4rp:OfficeLogo, url:error:com.fourjs.report.layoutnode.SVGPxmlImage$SVGException: (GS-31370) Loading SVG document from url file:/Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg failed (cause=null Enclosed Exception: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory))
and the following written to stdout
ERROR com.fourjs.report.stylesheet.PipeFromStreamThread - /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/OrderReport.4rp:OfficeLogo, url:error:com.fourjs.report.layoutnode.SVGPxmlImage$SVGException: (GS-31370) Loading SVG document from url file:/Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg failed (cause=null Enclosed Exception: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory)) com.fourjs.report.shared.AttributeException: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/OrderReport.4rp:OfficeLogo, url:error:com.fourjs.report.layoutnode.SVGPxmlImage$SVGException: (GS-31370) Loading SVG document from url file:/Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg failed (cause=null Enclosed Exception: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory)) at com.fourjs.report.shared.AttributeHelper.a(AttributeHelper.java:166) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.a(ImageBox.java:939) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.c(ImageBox.java:683) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.b(ImageBox.java:596) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.a(ImageBox.java:494) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.a(ImageBox.java:538) ~[gre.jar:?] at com.fourjs.report.layoutnode.LayoutNode.f(LayoutNode.java:2275) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.f(ImageBox.java:485) ~[gre.jar:?] at com.fourjs.report.stylesheet.PxmlLayouter.startElementEvent(PxmlLayouter.java:725) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.NSStyleSheet.b(NSStyleSheet.java:54) ~[gre.jar:?] at com.fourjs.report.stylesheet.HlPxmlToPxmlStyleSheet.a(HlPxmlToPxmlStyleSheet.java:3168) ~[gre.jar:?] at com.fourjs.report.stylesheet.NSStyleSheet.startElementEvent(NSStyleSheet.java:30) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.NSStyleSheet.b(NSStyleSheet.java:54) ~[gre.jar:?] at com.fourjs.report.stylesheet.BoxDecoratorStyleSheet.a(BoxDecoratorStyleSheet.java:337) ~[gre.jar:?] at com.fourjs.report.stylesheet.NSStyleSheet.startElementEvent(NSStyleSheet.java:30) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$AttributeSAX.a(RTLStyleSheet.java:2276) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$AttributeSAX.endElement(RTLStyleSheet.java:2300) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$ElementWrapper.m(RTLStyleSheet.java:1445) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$ElementWrapper.c(RTLStyleSheet.java:1250) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$ElementWrapper.a(RTLStyleSheet.java:1148) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$RTLInterpreter$RTLInterpreterNFA$RTLInterpreterParser.a(RTLStyleSheet.java:1995) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$RTLInterpreter$RTLInterpreterNFA$RTLInterpreterParser.d(RTLStyleSheet.java:1895) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet$RTLInterpreter$RTLInterpreterNFA$RTLInterpreterParser.c(RTLStyleSheet.java:1824) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLAutomaton$RTLNFA$a.b(RTLAutomaton.java:1773) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLAutomaton$RTLNFA$a.a(RTLAutomaton.java:1767) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLAutomaton$RTLNFA$a.b(RTLAutomaton.java:1735) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLAutomaton$RTLNFA$a.a(RTLAutomaton.java:1691) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLAutomaton$RTLNFA$a.consumeToken(RTLAutomaton.java:1683) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.RTLStyleSheet.startElementEvent(RTLStyleSheet.java:410) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.ScopeExtenderStyleSheet$a.b(ScopeExtenderStyleSheet.java:1174) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.ScopeExtenderStyleSheet$a.a(ScopeExtenderStyleSheet.java:1164) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.ScopeExtenderStyleSheet$a.a(ScopeExtenderStyleSheet.java:929) ~[gre.jar:?] at com.fourjs.report.stylesheet.rtl.ScopeExtenderStyleSheet.startElementEvent(ScopeExtenderStyleSheet.java:825) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.FGLReportToRTLInputStyleSheet.startElementEvent(FGLReportToRTLInputStyleSheet.java:105) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElementEvent(StyleSheet.java:459) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElementEvent(StyleSheet.java:459) ~[gre.jar:?] at com.fourjs.report.stylesheet.StyleSheet.startElement(StyleSheet.java:455) ~[gre.jar:?] at com.fourjs.report.stylesheet.LoaderStyleSheet.startElement(LoaderStyleSheet.java:79) ~[gre.jar:?] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:518) ~[?:?] at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183) ~[?:?] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353) ~[?:?] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2726) ~[?:?] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605) ~[?:?] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:114) ~[?:?] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542) ~[?:?] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889) ~[?:?] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825) ~[?:?] at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) ~[?:?] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224) ~[?:?] at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637) ~[?:?] at com.fourjs.report.stylesheet.PipeFromStreamThread.c(PipeFromStreamThread.java:137) ~[gre.jar:?] at com.fourjs.report.stylesheet.PipeFromStreamThread.run(PipeFromStreamThread.java:151) [gre.jar:?] Caused by: com.fourjs.report.layoutnode.SVGPxmlImage$SVGException: (GS-31370) Loading SVG document from url file:/Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg failed (cause=null Enclosed Exception: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory)) at com.fourjs.report.layoutnode.SVGPxmlImage.(SVGPxmlImage.java:52) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.a(ImageBox.java:935) ~[gre.jar:?] ... 57 more Caused by: org.apache.batik.transcoder.TranscoderException: null Enclosed Exception: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory) at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:136) ~[batik-transcoder-1.14.jar:?] at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:158) ~[batik-transcoder-1.14.jar:?] at com.fourjs.report.layoutnode.SVG2G2DTranscoder.(SVG2G2DTranscoder.java:49) ~[gre.jar:?] at com.fourjs.report.layoutnode.SVG2G2DTranscoder.(SVG2G2DTranscoder.java:37) ~[gre.jar:?] at com.fourjs.report.layoutnode.SVGPxmlImage.(SVGPxmlImage.java:48) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.a(ImageBox.java:935) ~[gre.jar:?] ... 57 more Caused by: java.io.FileNotFoundException: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory) at java.io.FileInputStream.open0(Native Method) ~[?:?] at java.io.FileInputStream.open(FileInputStream.java:213) ~[?:?] at java.io.FileInputStream.(FileInputStream.java:152) ~[?:?] at java.io.FileInputStream.(FileInputStream.java:106) ~[?:?] at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:84) ~[?:?] at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:180) ~[?:?] at org.apache.batik.util.ParsedURLData.openStreamInternal(ParsedURLData.java:554) ~[batik-util-1.14.jar:?] at org.apache.batik.util.ParsedURLData.openStream(ParsedURLData.java:476) ~[batik-util-1.14.jar:?] at org.apache.batik.util.ParsedURL.openStream(ParsedURL.java:440) ~[batik-util-1.14.jar:?] at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:159) ~[batik-anim-1.14.jar:?] at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:283) ~[batik-anim-1.14.jar:?] at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:129) ~[batik-transcoder-1.14.jar:?] at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:158) ~[batik-transcoder-1.14.jar:?] at com.fourjs.report.layoutnode.SVG2G2DTranscoder.(SVG2G2DTranscoder.java:49) ~[gre.jar:?] at com.fourjs.report.layoutnode.SVG2G2DTranscoder.(SVG2G2DTranscoder.java:37) ~[gre.jar:?] at com.fourjs.report.layoutnode.SVGPxmlImage.(SVGPxmlImage.java:48) ~[gre.jar:?] at com.fourjs.report.layoutnode.ImageBox.a(ImageBox.java:935) ~[gre.jar:?] ... 57 more /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/OrderReport.4rp:OfficeLogo, url:error:com.fourjs.report.layoutnode.SVGPxmlImage$SVGException: (GS-31370) Loading SVG document from url file:/Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg failed (cause=null Enclosed Exception: /Users/reubenbarclay/genero-files/samples/Reports/OrderReport/images/office_logo_new2.svg (No such file or directory)) Produced 0 page(s)
My opinion is that Java developers like the above type of error message. Genero developers don’t like it and say just give me an error number and one line of description!!!
There are two approaches you can use if you do want your program to continue on if an image file is missing.
First is to use the GRE_DEFAULT_IMAGE_URL environment variable. This should be set to the location of a image that you know is there. If an image is missing, then this image will be used instead.
The second approach is to use a Rendering Hint and in particular the pxmlIgnoreImageBoxErrors rendering hint. In the report program that you want to ignore the missing image, add the following …
LET renderingHints=om.SaxAttributes.create() CALL renderingHints.addAttribute("pxmlIgnoreImageBoxErrors","true") CALL fgl_report_setRenderingHints(renderingHints)
This will ignore the error and leave a blank space where the image should be.
Think very carefully if you choose either of these options. Whilst this might seem like a good idea for one of many images that appear in the detail of a report, it will also apply to images in the header such as company logos.