本主题重点介绍如何使用 C#** 将 PowerPoint 转换为 TIFF 以及配置环境和验证工作示例代码的详细配置步骤。您可以在 Windows、macOS 和 Linux 中的任何 .NET 支持的环境中使用此应用程序,以在 C# 中将 PPTX 转换为 TIFF。
使用 C# 将 PowerPoint 转换为 TIFF 的步骤
- 使用 NuGet 包管理器配置您的应用程序以安装 Aspose.Slides for .NET
- 使用 Presentation 类对象加载源演示文件以将其转换为 TIFF
- 初始化 TiffOptions 类对象以设置所需的图像选项
- 设置所需 TIFF 图像的 DPI 和大小
- 使用 Save 方法将演示文稿转换为 TIFF 图像
上述步骤仅在通过使用 Presentation 类加载源演示文件来启动该过程的情况下,使用几个 API 调用将演示文稿转换为 C# 中的 TIFF。然后通过使用 TiffOptions 类实例,在使用 Save 方法将演示文稿保存为磁盘上的 TIFF 图像之前设置输出 TIFF 图像选项,包括 DPI 和图像大小。
在 C# 中将 PPTX 转换为 TIFF 的代码
using System; | |
using System.Drawing; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace TestSlides | |
{ | |
public class PresentationToTiffConverter | |
{ | |
public static void CreateTiffImage() | |
{ | |
// Initialize a license to avoid watermark in the output Tiff Image | |
Aspose.Slides.License licenseSlides = new Aspose.Slides.License(); | |
licenseSlides.SetLicense("Aspose.Total.lic"); | |
// Initliazing the Presentation class to load the source presentation and converting to Tiff | |
using (Presentation SampleTiffPres = new Presentation("NewPresentation.pptx")) | |
{ | |
// Initialize the TiffOptions class | |
TiffOptions tiffOptions = new TiffOptions(); | |
// Setting the Tiff compression type | |
tiffOptions.CompressionType = TiffCompressionTypes.Default; | |
// Customizing the slides notes option inside exported Tiff | |
INotesCommentsLayoutingOptions notesOptions = tiffOptions.NotesCommentsLayouting; | |
notesOptions.NotesPosition = NotesPositions.BottomFull; | |
// Setting the Tiff image DPI. The resolution unit is always equal to 2-dots per inch | |
tiffOptions.DpiX = 200; | |
tiffOptions.DpiY = 100; | |
// Set the desired Tiff output Image Size | |
tiffOptions.ImageSize = new Size(1728, 1078); | |
// Save the source presentation to Tiff with set image size | |
SampleTiffPres.Save("ExpoertedTiff_out.tiff", SaveFormat.Tiff, tiffOptions); | |
} | |
} | |
} | |
} |
上面的示例也可用于使用相同的代码库*将 C# 中的 PPT 转换为 TIFF。 TiffOptions 类可以通过公开设置 CompressionType、PixelFormat、ShowHiddenSlides 和 NotesCommentsLayouting 等选项来进一步自定义输出 TIFF。上述应用程序无需安装 MS PowerPoint 或任何其他第三方工具即可将 PPTX 无缝转换为 TIFF。
在本教程中,我们通过执行简单的步骤和使用简单的 API 接口学习了在 C# 中从 PowerPoint 生成 TIFF。如果您对创建演示幻灯片图像感兴趣,请参阅 如何使用 C# 创建 PowerPoint 幻灯片图像 上的文章。