Hello,
We are converting an HTML content to PDF using Aspose.PDF for Java. We’ve noticed that if an html contains the <img>
tag with a source that cannot be found, then the the html cannot be converted, the following exception is thrown:
java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at com.aspose.pdf.internal.html.rendering.l0h.lI(Unknown Source)
at com.aspose.pdf.internal.html.rendering.l0h.lI(Unknown Source)
at com.aspose.pdf.internal.l43f.l0l.lf(Unknown Source)
at com.aspose.pdf.internal.l43u.ly.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l43h.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l42u.lj.lI(Unknown Source)
at com.aspose.pdf.internal.l42j.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l51p.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l43v.lt.lI(Unknown Source)
at com.aspose.pdf.internal.l43v.lf.lj(Unknown Source)
at com.aspose.pdf.internal.html.collections.lj.lj(Unknown Source)
at com.aspose.pdf.internal.html.collections.lj.hasNext(Unknown Source)
This can be reproduced with the latest 23.12 Aspose version, and we are using Java 17.
Sample java code:
HtmlLoadOptions options = new HtmlLoadOptions();
Document htmlDocument = new Document(RESOURCE_DIR + "img_src.html", options);
htmlDocument.save("img_src.pdf");
Sample html source:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<img src="no_image.png"/>
</div>
</body>
</html>
We would expect either a successful conversion without an image in the output pdf, or at least a ‘normal’ exception that we could catch and inform a user about their wrong input. Our users can add their own content and we cannot make sure their content is valid.
Why is there a dependency on the DatatypeConverter in case of an incorrect input? Is there a workaround to this except adding a jar with the DatatypeConverter class to the classpath that we are not willing to do?
Thank you for answers
Arjana