Search code examples
javasvgbatik

How to handle batik transcoder failure when svg contains broken image links?


I am using batik transcoder to convert my svg into png image.

I have external image sources in the svg image tags. Batik fails to do the conversion if any of my image link is broken.

I am getting the following error

org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
null:0
The URI https://image.example/example1.png
on element <image> can'"t be opened because:
The URI can't be opened:
Server returned HTTP response code: 403 for URL: https://image.example/example1.png
        at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
        at org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
        at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
        at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)

Is there anyway I can convert the svg even if the image tag is broken?


Solution

  • I was used batik-rasterizer 1.7 previously which faced the same problem as you.
    You can just update to batik-all in this version will do.

    gradle:
    compile group: 'org.codeartisans.thirdparties.swing', name: 'batik-all', version: '1.8pre-r1084380'