openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

BatikSVGDrawer does not load custom-protocol raster images through provided FSStreamFactory

Open devopsix opened this issue 3 years ago • 0 comments

Given an HTML document which embeds the same image having a custom-protocol URL 2 times, once through an HTML <img> tag and once through an SVG <image> tag in an inline SVG image:

<!DOCTYPE html>
<html lang="en">
<body>
<p><img src="foo:/flyingsaucer.png" /></p>
<p><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <image xlink:href="foo:/flyingsaucer.png" width="145" height="123" />
</svg></p>
</body>
</html>

And given an implementation of FSStreamFactory handling foo: URLs is provided:

public class FooStreamFactory implements FSStreamFactory {
    //...
}
new PdfRendererBuilder()
    .useProtocolsStreamImplementation(new FooStreamFactory(), "foo")
    .useSVGDrawer(new BatikSVGDrawer(SECURE, Set.of("foo")))
    .withHtmlContent(HTML, "")
    .toStream(out)
    .run();

When rendering this with Open PDF to HTML then a document showing 2 flying saucers images should be created.

But the resulting document contains only 1 flying saucers image and this warning message is logged:

com.openhtmltopdf.exception WARNING:: Couldn't draw SVG. => org.apache.batik.transcoder.TranscoderException:: null
Enclosed Exception:
null:0
The URI "foo:/flyingsaucer.png"
on element <image> can't be opened because:
The URI can't be opened:
Unable to make sense of URL for connection

Sample project with all code to reproduce above example

devopsix avatar Nov 22 '21 08:11 devopsix