这个快速操作主题包含有关如何在 Java 中将 PDF 转换为 TIFF 的信息。它包括配置环境的所有必要信息以及完成任务的详细步骤。用于将PDF 转换为 TIFF Java 代码与所需 TIFF 图像的自定义一起提供。
在 Java 中将 PDF 转换为 TIFF 的步骤
- 配置应用程序以从 Maven 存储库添加对 Aspose.PDF 的引用,以将 PDF 转换为 TIFF 图像
- 使用 Document 类对象打开源输入 PDF 文件以转换为 TIFF 图像
- 设置所需 TIFF 图像的分辨率
- 初始化 TiffSettings 类对象以自定义输出 TIFF 图像
- 使用指定的分辨率和其他设置初始化和配置 TiffDevice 对象
- 使用 TiffDevice.process 方法将 PDF 文件保存为 TIFF
上述步骤提供了有关使用 Java* 将 PDF 转换为 TIFF 所需的库的详细信息以及详细的实施步骤序列。您可以从磁盘打开源 PDF 并将其转换为 TIFF,同时使用 TiffSettings 对象自定义输出文件。转换过程由 TiffDevice 对象执行,该对象使用分辨率和 TiffSettings 实例进行初始化,并包含将 PDF 转换为 TIFF 的 process 方法。
使用 Java 将 PDF 转换为 TIFF 的代码
package testpdf; | |
import com.aspose.pdf.Document; | |
import com.aspose.pdf.License; | |
import com.aspose.pdf.devices.ColorDepth; | |
import com.aspose.pdf.devices.CompressionType; | |
import com.aspose.pdf.devices.Resolution; | |
import com.aspose.pdf.devices.ShapeType; | |
import com.aspose.pdf.devices.TiffDevice; | |
import com.aspose.pdf.devices.TiffSettings; | |
public class PdfToTiff { | |
static void main(String[] args) throws Exception // Exception for PDF to TIFF | |
{ | |
// Instantiate a license to convert PDF to TIFF | |
License PdfToTiffLicense = new License(); | |
PdfToTiffLicense.setLicense("Aspose.Total.lic"); | |
// Open the source PDF document for conversion to TIFF | |
Document pdfToTiffDocument = new Document("Test.pdf"); | |
// Instantiate and initialize the resolution object for the output TIFF | |
Resolution resolution = new Resolution(300,300); | |
// Create and initialize TiffSettings object to customize the TIFF file | |
TiffSettings tiffFileSettings = new TiffSettings(); | |
tiffFileSettings.setCompression(CompressionType.CCITT4); | |
tiffFileSettings.setDepth(ColorDepth.Format4bpp); | |
tiffFileSettings.setShape(ShapeType.Portrait); | |
tiffFileSettings.setSkipBlankPages(true); | |
// Initializing TIFF device and set the resolution and TiffSettings | |
TiffDevice tiffDeviceObj = new TiffDevice(resolution, tiffFileSettings); | |
// Save PDF file to the TIFF image | |
tiffDeviceObj.process(pdfToTiffDocument, "PdfToTIFF_out.tif"); | |
System.out.println("Done"); | |
} | |
} |
要使用将 PDF 转换为 TIFF Java 代码,其中使用水平和垂直分辨率值为输出 TIFF 图像设置分辨率,但是,您也可以使用另一个重载。 TiffSettings 类包含许多其他属性,包括设置压缩类型、跳过空白页、形状类型、颜色深度、亮度和页面坐标类型。 TiffDevice 类包括许多其他构造函数来初始化其具有不同特征的对象,例如宽度、高度、页面大小、分辨率和多个变体中的 TiffSettings 实例。
在此示例中,我们探讨了如何轻松使用 Java 将 PDF 转换为 TIFF。如果您打算了解如何将图像转换为 PDF,请参阅 如何在 Java 中将图像转换为 PDF 上的文章。