Batik Bridge 1.17 jar could not access external resource

186 views Asked by At

I was using batik 1.16 in my project. There came a requirement to increase its version to 1.17. Actually while creating Document from SVG, we are loading a page from external resource, but Batik 1.17 throws exception while doing this. Any resolution to access external resource while using Batik 1.17.

Error:

createImageFromSVG [] 03 Nov 2023 12:45:37 ERROR [forensic.core.aspect.LoggingAspect.logAfterThrowing:98] An Exception occured!! : org.apache.batik.transcoder.TranscoderException: null Enclosed Exception: Could not access the current document URL when trying to load an external resource (eg https://something.jpg. The external resource will not be loaded as it is not possible to verify it comes from the same location as the document. at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:228) ~[batik-transcoder-1.17.jar:?] at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:92) ~[batik-transcoder-1.17.jar:?] at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142) ~[batik-transcoder-1.17.jar:?] at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:158) ~[batik-transcoder-1.17.jar:?] at com.brown.core.utils.SVGRasterizer.transcode(SVGRasterizer.java:47) ~[com.forensic.core-0.0.1-SNAPSHOT.jar:?]

1

There are 1 answers

0
Igor Luzhanov On

After the mentioned change ( https://issues.apache.org/jira/browse/BATIK-1349 ) was implemented in Batik 1.17, external resource loading is blocked by default.

To fix this, you need explicitly add next transcoding hint:

PNGTranscoder transcoder = new PNGTranscoder();
transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_ALLOW_EXTERNAL_RESOURCES, Boolean.TRUE);