Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with src attribute of <img > tag - with SVG and with absolute/relative path #353

Closed
ieugen opened this issue May 6, 2019 · 3 comments

Comments

@ieugen
Copy link
Contributor

ieugen commented May 6, 2019

Hello,

I've stumbeled on some bugs (I think) when using img tag with SVG.

If the SVG does not exist, it renders a very strange error - that is impossible to figure out the cause of, without debugging the java app. It is the first error bellow.

Also, I've notice some other issues:

Exception when using a SVG that does not exist: <img src="/my-missing.svg" />

com.openhtmltopdf.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 3; The element type "meta" must be terminated by the matching end-tag "</meta>".
	at com.openhtmltopdf.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:274) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.resource.XMLResource$XMLResourceBuilder.access$100(XMLResource.java:168) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.resource.XMLResource.load(XMLResource.java:85) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:335) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfBoxReplacedElementFactory.createReplacedElement(PdfBoxReplacedElementFactory.java:62) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcDimensions(BlockBox.java:767) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcDimensions(BlockBox.java:707) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:873) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.InlineBoxing.layoutInlineBlockContent(InlineBoxing.java:423) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.InlineBoxing.layoutContent(InlineBoxing.java:314) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutInlineChildren(BlockBox.java:1073) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.AnonymousBlockBox.layout(AnonymousBlockBox.java:48) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.layout(PdfBoxRenderer.java:335) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.run(PdfRendererBuilder.java:40) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.gr8pi.reportgen.openhtmltopdf.OpenHtmlToPdfRenderer.run(OpenHtmlToPdfRenderer.java:83) ~[reportgen-openhtmltopdf-4.9.0-SNAPSHOT.jar:na]
	at picocli.CommandLine.execute(CommandLine.java:906) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine.access$700(CommandLine.java:104) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine$RunLast.handle(CommandLine.java:1083) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine$RunLast.handle(CommandLine.java:1051) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine$AbstractParseResultHandler.handleParseResult(CommandLine.java:959) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine.parseWithHandlers(CommandLine.java:1242) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine.run(CommandLine.java:1701) [picocli-3.5.2.jar:3.5.2]
	at picocli.CommandLine.run(CommandLine.java:1631) [picocli-3.5.2.jar:3.5.2]
	at com.gr8pi.reportgen.openhtmltopdf.RenderPdfMain.run(RenderPdfMain.java:27) [reportgen-openhtmltopdf-4.9.0-SNAPSHOT.jar:na]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:813) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:797) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at com.gr8pi.reportgen.openhtmltopdf.RenderPdfMain.main(RenderPdfMain.java:21) [reportgen-openhtmltopdf-4.9.0-SNAPSHOT.jar:na]
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 3; The element type "meta" must be terminated by the matching end-tag "</meta>".
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:740) ~[na:1.8.0_212]
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:343) ~[na:1.8.0_212]
	at com.openhtmltopdf.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:271) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	... 48 common frames omitted
Caused by: org.xml.sax.SAXParseException: The element type "meta" must be terminated by the matching end-tag "</meta>".
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1239) ~[na:1.8.0_212]
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:659) ~[na:1.8.0_212]
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:728) ~[na:1.8.0_212]
	... 50 common frames omitted

Without leading slash (relative url): <img src="my-missing.svg" />

java.lang.IllegalArgumentException: Invalid URL port: "8080my-missing.svg"
	at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1394) ~[okhttp-3.14.1.jar:na]
	at okhttp3.HttpUrl.get(HttpUrl.java:917) ~[okhttp-3.14.1.jar:na]
	at okhttp3.Request$Builder.url(Request.java:165) ~[okhttp-3.14.1.jar:na]
	at com.gr8pi.reportgen.openhtmltopdf.OkHttpStreamFactory.getUrl(OkHttpStreamFactory.java:25) ~[reportgen-openhtmltopdf-4.9.0-SNAPSHOT.jar:na]
	at com.openhtmltopdf.swing.NaiveUserAgent.openStream(NaiveUserAgent.java:165) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfBoxUserAgent.getImageResource(PdfBoxUserAgent.java:80) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfBoxReplacedElementFactory.createReplacedElement(PdfBoxReplacedElementFactory.java:65) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcDimensions(BlockBox.java:767) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcDimensions(BlockBox.java:707) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:873) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.InlineBoxing.layoutInlineBlockContent(InlineBoxing.java:423) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.InlineBoxing.layoutContent(InlineBoxing.java:314) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutInlineChildren(BlockBox.java:1073) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.AnonymousBlockBox.layout(AnonymousBlockBox.java:48) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.layout(PdfBoxRenderer.java:335) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.run(PdfRendererBuilder.java:40) ~[openhtmltopdf-pdfbox-0.0.1-RC20.jar:na]
	at com.gr8pi.reportgen.openhtmltopdf.OpenHtmlToPdfRenderer.run(OpenHtmlToPdfRenderer.java:83) ~[reportgen-openhtmltopdf-4.9.0-SNAPSHOT.jar:na]
@danfickle
Copy link
Owner

Yes, you have found a couple of bugs:

  • There is no error handling when an external svg image can not be loaded.
  • The loader for XML does not use the URL resolver.

I’ve been a bit quiet lately, but I will fix these, so thanks for reporting.

@danfickle
Copy link
Owner

Hi @ieugen,

I've added some better error handling and a test. However, I've just re-looked at your stack traces and noticed a couple of things. I'm not sure I've addressed the correct problems.

For the relative case, I think the problem might be with the URI resolver and a document at the root of a web server. Maybe, it's not adding a slash. Is the XHTML document literally the index page. ie http:example.com:8080 with no path? If so, try adding a slash to the end, possibly.

I'm also not sure what's going on in the absolute case. It should definitely be going through a URI resolver.

Anyway, I'm going to do a release in the next couple of days, so if you have time, maybe you could give it another try?

@danfickle
Copy link
Owner

Please reopen as required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants