danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.93k stars 359 forks source link

Cannot display SVG with inline png image (png on multiple lines) #875

Open victoroniga opened 2 years ago

victoroniga commented 2 years ago

Had a 6 hour debugging session to figure out why my SVG is not displayed with inline png image. I'm using openhtmltopdf (and svg-support) version 1.0.10 (with batik version 1.14) and openjdk 11.0.9_11.

I suspect line 125 in SVGImageExtension to be in error and further line 34 in the same file. Since the inline png image is provided as data:image/png, the lines 125/34 tries to resolve its URI, which leads to the following error in java.net.URI: Illegal character in opaque part.

https://github.com/danfickle/openhtmltopdf/blob/780ba564839f1ad5abfa5df12e4aebb9dd6782d2/openhtmltopdf-svg-support/src/main/java/com/openhtmltopdf/svgsupport/SVGImageExtension.java#L125 https://github.com/danfickle/openhtmltopdf/blob/780ba564839f1ad5abfa5df12e4aebb9dd6782d2/openhtmltopdf-svg-support/src/main/java/com/openhtmltopdf/svgsupport/SVGImageExtension.java#L34

The issue only happens when the inline png is displayed on multiple lines. This happens for example with Adobe Illustrator 17.0.2, SVG Export Plug-In. So, a multi line inline png (using \n character or even a space) generated by another tool gets parsed using URI Java API which leads to an error.

In my debug session I have bypassed somehow the line 125 in SVGImageExtension. As a consequence, the SVG has been correctly displayed in the generated PDF file.

Thanks for your support.