A TIFF, which stands for Tag Image File Format, is a computer file used to store raster graphics and image information. It is widely used due to its flexibility, inclusiveness, and independence. This article will introduce how to convert PDF to TIFF using Java codes from the two aspects below.
l Convert
all pages of a PDF file to TIFF
l Convert
some specified pages of a PDF file to TIFF
DEPENDENCY
First of all, you’re required to get the package of a free third-party library called Free Spire.PDF for Java from this link, and then find Spire.Pdf.jar in the “lib” folder, finally add it to your Java program. Or if you use Maven, just import the following codes in the pom.xml file to easily add the JAR 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.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
USING THE CODE
Convert All Pages of a PDF File to TIFF
The following steps show how to convert all pages of a PDF file to TIFF.
l Initialize a PdfDocument object.
l Load a PDF sample
document using PdfDocument.loadFromFile()
method.
l Save all pages of the document to a TIFF file using PdfDocument.saveToTiff(String tiffFilename) method.
import com.spire.compression.TiffCompressionTypes;
import com.spire.pdf.PdfDocument;
public class PDFToTIFF {
public static void main(String[] args) {
//Initialize a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load a PDF sample document
pdf.loadFromFile("sample.pdf");
//Save all pages of the document to Tiff
pdf.saveToTiff("output/PDFtoTiff.tiff");
}
}Convert Some Specified Pages of a PDF File to TIFF
The following are steps to convert specified pages of a PDF file to TIFF.
l Initialize a PdfDocument object.
l Load a PDF sample document using PdfDocument.loadFromFile() method.
l Save specified pages of the document to a TIFF file using PdfDocument.saveToTiff(String tiffFilename, int startPage, int endPage, int dpix, int dpiy) method.
import com.spire.pdf.PdfDocument;
public class PDFToTIFF {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a PDF sample document
pdf.loadFromFile("sample.pdf");
//Save specified pages of the document to TIFF and set horizontal and vertical resolution
pdf.saveToTiff("output/ToTiff2.tiff",0,1,400,600);
}
}
No comments:
Post a Comment