Java (481)
The Tagged Image File Format (TIFF) is a relatively flexible image format which has the advantages of not requiring specific hardware, as well as being portable. Spire.PDF for Java supports converting TIFF to PDF and vice versa. This article will show you how to programmatically convert PDF to TIFF using it from the two aspects below.
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>11.12.16</version>
</dependency>
</dependencies>
Convert All Pages of a PDF File to TIFF
The following steps show you how to convert all pages of a PDF file to a TIFF file.
- Create a PdfDocument instance.
- Load a PDF sample document using PdfDocument.loadFromFile() method.
- Save all pages of the document to a TIFF file using PdfDocument.saveToTiff(String tiffFilename) method.
- Java
import com.spire.compression.TiffCompressionTypes;
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 all pages of the document to Tiff
pdf.saveToTiff("output/PDFtoTiff.tiff");
}
}

Convert Some Specified Pages of a PDF File to TIFF
The following steps are to convert specified pages of a PDF document to a TIFF file.
- Create a PdfDocument instance.
- Load a PDF sample document using PdfDocument.loadFromFile() method.
- Save specified pages of the document to a TIFF file using PdfDocument.saveToTiff(String tiffFilename, int startPage, int endPage, int dpix, int dpiy) method.
- Java
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);
}
}

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.
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>11.12.16</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);
}
}

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.
Multi-column PDFs are commonly used in magazines, newspapers, research articles, etc. With Spire.PDF for Java, you can create multi-column PDFs from code easily. This article will show you how to create a two-column PDF from scratch in Java applications.
Install Spire.PDF for Java
First of all, you need 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 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>11.12.16</version>
</dependency>
</dependencies>
Create a Two-Column PDF from Scratch
The detailed steps are as follows:
- Create a PdfDocument object.
- Add a new page in the PDF using PdfDocument.getPages().add() method.
- Add a line and set its format in the PDF using PdfPageBase.getCanvas().drawLine() method.
- Add text in the PDF at two separate rectangle areas using PdfPageBase.getCanvas().drawString() method.
- Save the document to PDF 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.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class TwoColumnPDF {
public static void main(String[] args) throws Exception {
//Creates a pdf document
PdfDocument doc = new PdfDocument();
//Add a new page
PdfPageBase page = doc.getPages().add();
//Set location and width
float x = 0;
float y = 15;
float width = 600;
//Create pen
PdfPen pen = new PdfPen(new PdfRGBColor(Color.black), 1f);
//Draw line on the PDF page
page.getCanvas().drawLine(pen, x, y, x + width, y);
//Define paragraph text
String s1 = "Spire.PDF for Java is a PDF API that enables Java applications to read, write and "
+ "save PDF documents without using Adobe Acrobat. Using this Java PDF component, developers and "
+ "programmers can implement rich capabilities to create PDF files from scratch or process existing"
+ "PDF documents entirely on Java applications (J2SE and J2EE).";
String s2 = "Many rich features can be supported by Spire.PDF for Java, such as security settings,"
+ "extract text/image from the PDF, merge/split PDF, draw text/image/shape/barcode to the PDF, create"
+ "and fill in form fields, add and delete PDF layers, overlay PDF, insert text/image watermark to the "
+ "PDF, add/update/delete PDF bookmarks, add tables to the PDF, compress PDF document etc. Besides, "
+ "Spire.PDF for Java can be applied easily to convert PDF to XPS, XPS to PDF, PDF to SVG, PDF to Word,"
+ "PDF to HTML and PDF to PDF/A in high quality.";
//Get width and height of page
double pageWidth = page.getClientSize().getWidth();
double pageHeight = page.getClientSize().getHeight();
//Create solid brush objects
PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.BLACK));
//Create true type font objects
PdfTrueTypeFont font= new PdfTrueTypeFont(new Font("Times New Roman",Font.PLAIN,14));
//Set the text alignment via PdfStringFormat class
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
//Draw text
page.getCanvas().drawString(s1, font, brush, new Rectangle2D.Double(0, 20, pageWidth / 2 - 8f, pageHeight), format);
page.getCanvas().drawString(s2, font, brush, new Rectangle2D.Double(pageWidth / 2 + 8f, 20, pageWidth / 2 - 8f, pageHeight), format);
//Save the document
String output = "output/createTwoColumnPDF.pdf";
doc.saveToFile(output, FileFormat.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.