Java: Convert TIFF to PDF

TIFF or TIF files are image files saved in the tagged image file format. They are often used for storing high-quality color images. Sometimes, you may wish to convert TIFF files to PDF so you can share them more easily. In this article, you will learn how to achieve this task programmatically in Java using Spire.PDF for Java library.

Install Spire.PDF for Java

First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>10.4.4</version>
    </dependency>
</dependencies>
    

Convert TIFF to PDF in Java

The following are the steps to convert a TIFF file to PDF:

  • Create an instance of PdfDocument class.
  • Add a page to the PDF using PdfDocument.getPages().add() method.
  • Create a PdfImage object from the TIFF image using PdfImage.fromFile() method.
  • Draw the image onto the page using PdfPageBase.getCanvas().drawImage() method.
  • Save the result file using PdfDocument.saveToFile() method.
  • Java
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.graphics.PdfImage;

public class ConvertTiffToPdf {
    public static void main(String[] args){
        //Create a PdfDocument instance
        PdfDocument doc = new PdfDocument();
        //Add a page
        PdfPageBase page = doc.getPages().add();
        
        //Create a PdfImage object from the TIFF image
        PdfImage tiff = PdfImage.fromFile("Input.tiff");
        //Draw the image to the page
        page.getCanvas().drawImage(tiff, 20, 0, 450, 450);
        
        //Save the result file
        doc.saveToFile("TiffToPdf.pdf", FileFormat.PDF);
    }
}

Java: Convert TIFF to PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.