Scalable Vector Graphics(SVG) is a popular digital image file format with optimized characteristics. SVG graphics are scalable, programmable, and capable of powerful animations. In addition, SVG images are based on vector files that accumulate images as a set of points and their connections with one another. On the other side, PDF is another enterprise-level vector-graphic format. It is widely used in the corporate sector due to its security, compression, and other vigorous features. In this blog post, we will go through how to convert SVG to PDF programmatically in a Java-based application.
We will cover the following points in this article:
- Java library for SVG to PDF conversion - Installation steps
- Convert SVG to PDF programmatically in Java
Java library for SVG to PDF conversion - Installation steps
Aspose.HTML for Java offers file format conversions of multiple formats such as SVG to PDF, HTML to PDF, etc. Not only file format conversion but also provides file editing, creation, and manipulation of file data. To convert SVG to PDF programmatically, let’s set up this Java library by following the easy steps.
You can either download the jar files or configure the Maven configurations by placing the following repository and dependency in the pom.xml.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-html</artifactId> <version>21.12</version> <classifier>jdk1.8</classifier> </dependency>
Convert SVG to PDF programmatically in Java
In this section, we will go through the code snippet of Java SVG to PDF conversion library.
Following are the steps to convert SVG to PDF using the Java library:
- Initialize an object of the SVGDocument class with the source SVG file.
- Create an object of pdfSaveOptions class to access advance methods related to document setJpegQuality, setImageCompression etc.
- Call this setJpegQuality(int value) method to specify the quality of JPEG compression for images.
- Invoke convertSVG(SVGDocument document, PdfSaveOptions options, java.util.Collection providedInputStreams) method to convert SVG image to PDF file.
Now, copy and paste the following code snippet to convert SVG to PDF programmatically.
SVG to PDF
Get a Free License
We are ending this blog post here. It is important to note that we have gone through the installation procedure of the Java library for SVG to PDF conversion and we have practically performed how to convert SVG to PDF programmatically in Java. However, you may integrate this library in your Java application if you are looking to convert files from one format to another programmatically. Moreover, you may explore Aspose.HTML by going through the documentation. In addition, conholdate.com will soon publish interesting articles on further topics. Therefore, please stay connected for the latest updates.
Ask a question
In case of any queries please feel free to write to us at the forum.