We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception when converting html to pdf with empty div with display: flex

Hello,

Is the ‘display: flex’ fully supported when converting html to pdf using Java? We observed a case when there is an html with an empty div, and that div has a style display: flex, e. g:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
    <div style="display: flex;"></div>
</div>
</body>
</html>

If we try to convert the html, the following exception is thrown:

Exception in thread "main" java.lang.NullPointerException
at com.aspose.pdf.internal.l44t.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l0l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l0l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l0l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l0l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l0l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lc.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l0l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l1l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l1l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l1l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l1l.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l3n.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l3n.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l3n.lj(Unknown Source)
at com.aspose.pdf.internal.l44l.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l3n.lI(Unknown Source)
at com.aspose.pdf.internal.l44l.l4if.l2n(Unknown Source)
at com.aspose.pdf.internal.l40t.lb.lf(Unknown Source)
at com.aspose.pdf.internal.l41y.lk.l0p(Unknown Source)
at com.aspose.pdf.internal.l41l.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l41l.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l41l.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l40if.lj.lI(Unknown Source)
at com.aspose.pdf.internal.l40l.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l48y.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l40n.lt.lI(Unknown Source)
at com.aspose.pdf.internal.l40n.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)
at com.aspose.pdf.internal.l48y.lI.lI(Unknown Source)
at com.aspose.pdf.internal.html.rendering.HtmlRenderer.render(Unknown Source)
at com.aspose.pdf.internal.html.rendering.HtmlRenderer.render(Unknown Source)
at com.aspose.pdf.internal.html.rendering.Renderer.render(Unknown Source)
at com.aspose.pdf.internal.html.rendering.Renderer.render(Unknown Source)
at com.aspose.pdf.l6y.lI(Unknown Source)
at com.aspose.pdf.l6y.lI(Unknown Source)
at com.aspose.pdf.ADocument.lI(Unknown Source)
at com.aspose.pdf.ADocument.<init>(Unknown Source)
at com.aspose.pdf.Document.<init>(Unknown Source)
at lt.test.SvgTest.generateComplexHtml(SvgTest.java:58)
at lt.test.SvgTest.main(SvgTest.java:31)

If the div is not empty or the display value is not flex, the content is successfully converted to pdf.
The code used for conversion:

    HtmlLoadOptions options = new HtmlLoadOptions();
	IDocument document = new Document(RESOURCE_DIR + "input.html", options);
	document.save("output.pdf");

Reproduced with 21.8 version

Arjana Bivainiene

@arjana

I have been able to reproduce the issue on our end. A ticket with ID PDFJAVA-40870 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.