How to raise a Java exception if the rendered SVG has an error, after conversion from PDF to SVG


I have written below code for converting PDF to SVG.

doc = new Document(pathToInputPdfFile);
com.aspose.pdf.Page pdfPage = doc.getPages().get_Item(1);
newDocument = new Document();
SvgSaveOptions saveOptions = new SvgSaveOptions();
saveOptions.CompressOutputToZipArchive = false;, saveOptions);

Its is working fine with PDFs without images. If there is any image in the PDF, rendered SVG is showing below error. However the java code executed doesn’t show any error in the console though rendered SVG has an error.

This page contains the following error:

error on line 123 at column 7: PCDATA invalid char value 3

Below is the rendered of the page up to the first error:

Please let me know if there is a way where I can raise exception when the SVG has errro in it.



Thanks for contacting support.

I have tested the whole scenario with one of my sample PDFs while using Aspose.Pdf for Java 17.6 and I was unable to notice the issue. The PDF (containing image), was rendered as SVG correctly, without throwing any error. For your reference, I have attached input/output file(s) as well. (22.5 KB)
PDFWithImage.pdf (16.2 KB)

Please note that sometimes issue may be related with specific input document, so we will really appreciate if you please share your sample input document, with which you are facing the issue. We will test the scenario again in our environment and respond you accordingly.

Hi Asad Ali,

Can you please try to convert pdf in above link to SVG. Please let me know how i can resolve the two issues that comes up. One is with pdfcollection and other one is in rendered svg



Thanks for sharing the document.

I have tried to convert the document into SVG with Aspose.Pdf for Java 17.6 and was unable to notice any issue. The SVG was generated without any error and rendered correctly when opened in browser. Please note that I have tested the scenario in an environment (Eclipse Neon.2 Release (4.6.2), JDK 1.8, Windows 10 EN x64). For your reference, I have attached an output as well. (88.8 KB)

Please try scenario with latest version of the API, at your end and in case if you still face any issue, please share your environment details with us, so that we can test the scenario in specific environment and address it accordingly.