Being the software and hardware-independent format, PDF gives an outstanding user experience as compared to other document formats. The consistent layout of PDF makes it a universal format. Therefore, in various scenarios, the documents or images are converted to PDF before they are shared or exchanged. In this article, you will learn how to convert animated GIF images to PDF using Java. Particularly, we will convert each frame in a GIF to an image in a PDF file.
- Java GIF to PDF Converter API
- Convert GIF to PDF using Java
- Convert Particular GIF Frame to PDF
- Set Page Size in GIF to PDF Conversion
- Set PDF Document Info in GIF to PDF Conversion
- Get a Free API License
Java GIF to PDF Converter API
Aspose.Imaging for Java is designed to perform image processing operations from within your Java applications. The API lets you manipulate popular image formats seamlessly. Furthermore, its built-in converter API allows you to convert images from one format to another. Aspose.Imaging for Java can be downloaded as JAR or installed using the following Maven configurations.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging-java</artifactId>
<version>20.12</version>
<classifier>jdk16</classifier>
</dependency>
Convert GIF to PDF using Java
The following are the steps to convert a GIF image to PDF using Aspose.Imaging.
- Load the GIF image using the Image class.
- Create an instance of PdfOptions class.
- Convert GIF to PDF using Image.save(String, PdfOptions) method.
The following code sample shows how to convert a GIF to PDF using Java.
Animated GIF
Converted PDF
Convert Particular GIF Frame to PDF
You can also convert a particular frame or a range of frames in GIF to PDF. The following are the steps to perform this operation.
- Load the GIF image using the Image class.
- Create an instance of PdfOptions class.
- Specify the frame(s) you want to convert using PdfOptions.setMultiPageOptions(MultiPageOptions) method.
- Save the converted PDF using Image.save(String, PdfOptions) method.
The following code sample shows how to convert particular frame(s) of a GIF to PDF using Java.
Set Page Size in GIF to PDF Conversion
Aspose.Imaging for Java also lets you specify the dimensions of the pages in the converted PDF document. The following are the steps to set the height and width of the pages in GIF to PDF conversion.
- Load the GIF image using the Image class.
- Create an instance of PdfOptions class.
- Set height and width of the pages using PdfOptions.setPageSize(new SizeF(float, float)) method.
- Convert GIF to PDF using Image.save(String, PdfOptions) method.
The following code sample shows how to set the page size in Java GIF to PDF conversion.
Java GIF to PDF - Set Document Info
The PDF format allows you to set the additional information about the document including author, subject, title, and keywords. You can also set these properties for the converted PDF document in GIF to PDF conversion. The following are the steps to set the document information of the PDF.
- Load the GIF image using the Image class.
- Create an instance of PdfOptions class.
- Create an instance of PdfDocumentInfo class.
- Set properties of the document such as author.
- Set document info of the PDF using PdfOptions.setPdfDocumentInfo(DocumentInfo) method.
- Convert GIF to PDF using Image.save(String, PdfOptions) method.
The following code sample shows how to set PDF document info in GIF to PDF conversion.
Get a Free API License
In case you want to try the API without evaluation limitations, you can get a free temporary license.
Conclusion
In this article, you have learned how to convert GIF images to PDF using Java. Furthermore, different options have been discussed to customize GIF to PDF conversion. You can explore more about the Java image processing API using documentation.
See Also
Info: You may want to check out the FREE Text to GIF Converter Aspose recently developed.