
How to Convert GIF to PDF in Java
PDF is a widely used vector‑based document format, while GIF is a raster image format popular for animations. This guide shows how to transform GIF images into PDF documents using Java. By integrating the Aspose.Words Java library, you can automate GIF‑to‑PDF conversion and add powerful document capabilities to your applications.
You will go through the following points:
GIF to PDF Conversion - Java API Installation
Adding the Aspose.Words library to a Java project is straightforward. You can either download the JAR file directly or include it via Maven. Add the repository and dependency to your pom.xml as shown below.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>22.10</version>
<classifier>jdk17</classifier>
</dependency>
How to Convert GIF to PDF in Java
After adding the Aspose.Words dependency, follow these steps to convert a GIF file to a PDF document.
- Instantiate an instance of the Document class.
- Initialize a DocumentBuilder object and bind it to the Document.
- Load the source GIF file and create an image stream with the createImageInputStream method, passing a File object.
- Create an ImageReader and use getImageReaders to obtain an iterator of suitable readers for the stream.
- Call the setInput method to set the image stream as the reader’s input.
- Retrieve the total number of frames using getNumImages.
- Loop through each frame.
- Insert a section break before each new page (for multi‑frame images) with the insertBreak method.
- Select the active frame by invoking the read method.
- Obtain the current page setup via getPageSetup and store it in a PageSetup object.
- Set the page width with setPageWidth.
- Set the page height with setPageHeight.
- Insert the image at the top‑left corner using the insertImage method.
- Save the document as a PDF by calling the save method.
Copy & paste the following code into your main file to convert GIF to PDF in Java:
The output can be seen in the image below:

Get a Free License
You can get a free temporary license to try the API without evaluation limitations.
Summing up
We are ending this blog post here. you have gone through how to convert GIF to PDF in Java using a few lines of source code. In addition, you may install this document processing library to build a GIF to PDF converter programmatically in Java. Moreover, you can visit the documentation to learn other interesting features.
Moreover, we suggest you follow our Getting Started guide.
Finally, conholdate.com is writing new blog posts. So, please stay in touch for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
FAQs
How do I convert a GIF to PDF in Java?
You can perform GIF to PDF conversion programmatically using this Java library. Further, please visit this link to get the cope snippet.