PDF has been ruling the world of digital document formats for many years for printing, sharing, exchanging, and archiving documents. However, PDF may not be suitable in certain situations such as displaying it on a web page as it requires browser support or additional plugins. In such cases, SVG comes as an alternative. SVG files can easily be displayed on the web pages without disturbing the user experience because of its screen resolution independence. Hence, PDF to SVG conversion takes place in such cases. In this article, you are going to learn how to convert the PDF files to SVG format using Java.
- Java PDF to SVG Converter API – Free Download
- PDF to SVG Conversion
- Convert PDF to SVG with Additional Options
Java PDF to SVG Converter API – Free Download
Aspose.PDF for Java is a PDF manipulation API that has a built-in PDF converter. The API lets you convert the PDF documents into SVG format with high accuracy. You can either download the API or get it installed within your Java applications using the following Maven configurations.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<classifier>jdk17</classifier>
</dependency>
PDF to SVG Java Conversion
The following are the steps to convert a PDF file to SVG format using Aspose.PDF for Java.
- Load the PDF file using the Document class.
- Create an object of the SvgSaveOptions class.
- Save the PDF as SVG using Document.save(String, SvgSaveOptions) method.
The following code sample shows how to convert a PDF to SVG using Java.
Convert PDF to SVG with Additional Options
Aspose.PDF also provides some additional options to customize the PDF to SVG conversion. The SvgSaveOptions class lets you accomplish this using the following options.
- CompressOutputToZipArchive
- CustomStrategyOfEmbeddedImagesSaving
- ScaleToPixels
- TreatTargetFileNameAsDirectory
The following are the steps to convert PDF to SVG with additional options.
- Load the PDF file using the Document class.
- Create an object of the SvgSaveOptions class.
- Set the desired SVG option such as CompressOutputToZipArchive.
- Save the PDF as SVG using Document.save(String, SvgSaveOptions) method.
The following code sample shows how to perform a customized PDF to SVG conversion.
Conclusion
In this article, you have seen how to convert PDF files to SVG using Java. The code samples have also demonstrated the customized conversion with additional options. You can explore more about the Java PDF API using the documentation.