0

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?

Queen
  • 21
  • 1
  • 2
  • 5
Jerry
  • 987
  • 4
  • 16
  • 46
  • Your stacktraces do not contain linenumbers. They are very useful in navigating sources, which is necessary here to see if there is any logic that can be triggered to handle such an error. You might find the time spend to figure out why they aren't there, and fix it, well spent. – Thorbjørn Ravn Andersen May 05 '16 at 07:24
  • Write some java code to traverse the DOM and check the links before transcoding. If the links are broken, replace or remove them. – Robert Longson May 05 '16 at 07:47
  • @Jerry, what is your excepted output – Ravipati Praveen Apr 12 '18 at 10:26
  • if the image tag is broken i don't want to show anything in that tag and I am expecting the png file to be generated – Jerry Apr 12 '18 at 10:28

2 Answers2

1

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'

yean
  • 1,307
  • 12
  • 8
-1

Attached a screenshot. After long debug found that issue caused due to UknownHostException.

org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
null:0
The URI "https://url.com/MIP20212_support.png"
on element <image> can't be opened because:
JDK URL is corrupt or unsupported variant

enter image description here

Sandeep M
  • 248
  • 3
  • 6
  • This is not an answer to my question. For any reason( be it unknown host or 404 or anything) if one of the image url is broken batik fails to do the conversion. Question is how can I continue with the conversion even if there is a broken link (either show no image there or show a broke image ) – Jerry Apr 06 '20 at 05:10