Convert SVG image to PDF using Aspose.PDF for Java - output is incorrect

Hello,

We are using Aspose for Java to convert html content to pdf, and the html may contain one or multiple svg images. But the problem is that either conversion fails in case of some svg images, or the output pdf is incorrect.

For a few problem images, I tried to make conversion using SvgLoadOptions directly, without using html:

Document svgDocument = new Document(RESOURCE_DIR + "image1.svg", new SvgLoadOptions());
svgDocument.save("output1.pdf");

In this case, the images are converted to pdf in all cases, but part or most of the output image is incorrect. I attach a file svg_to_pdf.zip with three cases, where you can see the input svg (e. g. case1/image1.svg), the output pdf (e. g. case1/output1.pdf) and the difference (e. g. case1/comparison_problems1.png).

If I try to reference the same images within the html, then the conversion fails with the following stack trace:

Exception in thread "main" class com.aspose.html.internal.ms.System.ArgumentException: 
Argument width[0] or height[0] cannot be less or equal to zero
com.aspose.html.internal.ms.core.drawing.a.c.a(Unknown Source)
com.aspose.html.internal.ms.System.Drawing.Bitmap.asBufferedImage(Unknown Source)
com.aspose.html.internal.ms.System.Drawing.Bitmap.<init>(Unknown Source)
com.aspose.html.internal.ms.System.Drawing.Bitmap.<init>(Unknown Source)
com.aspose.html.internal.p95.z7.m1(Unknown Source)
com.aspose.html.internal.p95.z7.m1(Unknown Source)
com.aspose.html.internal.p105.z2.m1(Unknown Source)
...

Sample html template.html:

<!DOCTYPE html>
<html lang="en">
<head>
        <title>SVG export test</title>
        <meta charset="utf-8"/>
 </head>
<body>

<div>
        <img src="image1.svg" alt="" />
</div>
</body>
</html>

Java code:

HTMLDocument htmlDocument = new HTMLDocument(RESOURCE_DIR + "template.html");
HtmlRenderer htmlRenderer = new HtmlRenderer();

try(OutputStream outputStream = new FileOutputStream("output.pdf"))
{
	htmlRenderer.render(new PdfDevice(new PdfRenderingOptions(), outputStream), htmlDocument);
}

Is it a bug to be fixed by Aspose, or are there any other reasons why the conversion cannot be performed successfully?

Sample files:

svg_to_pdf.zip (594.7 KB)

@arjana,

Thanks for sharing further details.

We have logged an investigation ticket as PDFJAVA-39404 in our issue tracking system. We will further look into details of it and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFJAVA-39404) have been fixed in Aspose.PDF for Java 21.6.