这篇快速文章包含有关如何在 C#** 中将 PDF 转换为 TIFF 的信息。它提供了配置环境所需的所有信息以及完成任务的详细步骤。将PDF 转换为 TIFF C# 代码与输出 TIFF 图像的自定义一起演示。
在 C# 中将 PDF 转换为 TIFF 的步骤
- 使用 Nuget 包管理器配置项目以将 Aspose.PDF 添加到应用程序中
- 将示例输入 PDF 文件加载到 Document 类对象以转换为 TIFF 图像
- 设置输出 TIFF 图像的分辨率
- 实例化并配置 TiffSettings 类对象以自定义输出 TIFF 图像
- 使用指定的分辨率和其他设置创建和配置 TiffDevice 对象
- 使用 TiffDevice.Process 函数将加载的 PDF 文件保存为 TIFF
上述步骤提供了使用 C#* 将 PDF 转换为 TIFF 所需的必要库的链接以及正确实施的详细步骤序列。您可以从磁盘加载源 PDF 并将其简单地转换为 TIFF,但是为了演示自定义,此处配置了 TiffSettings 对象。实际转换由 TiffDevice 对象执行,该对象使用分辨率和 TiffSettings 实例进行初始化,并包含将 PDF 转换为 TIFF 的 Process 函数。
使用 C# 将 PDF 转换为 TIFF 的代码
using Aspose.Pdf; | |
using Aspose.Pdf.Devices; | |
namespace AsposePdf | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Initialize and load the Aspose.PDF license to avoid evaluation watermark in the output TIFF image | |
Aspose.Pdf.License license = new Aspose.Pdf.License(); | |
license.SetLicense("Aspose.Pdf.lic"); | |
// Open the sample input PDF document for conversion to TIFF | |
Document pdfDocument = new Document("SampleInput.pdf"); | |
// Create and initialize the resolution object for the output TIFF | |
Resolution resolution = new Resolution(300,300); | |
// Instantiate and initialize TiffSettings object to customize the TIFF file | |
TiffSettings tiffFileSettings = new TiffSettings | |
{ | |
Compression = CompressionType.CCITT4, | |
Depth = ColorDepth.Format4bpp, | |
Shape = ShapeType.Portrait, | |
SkipBlankPages = true | |
}; | |
// Create TIFF device and initialize with resolution and TiffSettings | |
TiffDevice tiffDeviceObj = new TiffDevice(resolution, tiffFileSettings); | |
// Convert the input PDF file to the TIFF image | |
tiffDeviceObj.Process(pdfDocument, "AllPagesToTIFF_out.tif"); | |
System.Console.WriteLine("Done"); | |
} | |
} | |
} |
演示将 PDF 转换为 TIFF C#* 代码,其中使用水平和垂直分辨率值为输出 TIFF 图像设置分辨率,但是您也可以使用另一个重载。 TiffSettings 类包含很多属性,如跳过空白页、设置压缩类型、颜色深度、形状类型、亮度和页面坐标类型。 TiffDevice 类包含许多构造函数来初始化其具有不同特征的对象,如分辨率、页面大小、宽度、高度和 TiffSettings 实例的多种组合。
我们已经学习了如何使用 C# 将 PDF 转换为 TIFF,但是如果您想学习其他类型的转换,例如 PDF 到 Word,请参阅 如何使用 C# 将 PDF 转换为 Word 上的文章。