在 C# 中将 ODP 转换为 PDF

本简短主题重点介绍如何在 C# 中ODP 转换为 PDF。它包含项目设置、编程任务列表以及使用简单的 API 接口在 C# 中将 ODP 转换为 PDF 的工作示例代码。该应用程序可在 macOS、Windows 和 Linux 内任何支持 .NET 的环境中使用。

使用 C# 将 ODP 保存为 PDF 的步骤

  1. 建立开发环境安装Aspose.Slides for .NET使用C#将ODP转换为PDF
  2. 使用 Presentation 类的实例加载源 ODP 演示文稿以进行 ODP 到 PDF 的转换
  3. 创建 PdfOptions 类的实例并设置所需的 PDF 文件选项
  4. 将加载的 ODP 作为 PDF 文件保存在磁盘上

通过遵循上述步骤,您可以使用 C# 轻松将 ODP 导出为 PDF。该过程首先从磁盘访问源 ODP 文件,然后创建 PdfOptions 类的实例来设置所需的 PDF 文件选项。最后,ODP 将在磁盘上呈现为 PDF 文件。

用 C# 将 ODP 转换为 PDF 的代码

using System;
using Aspose.Slides;
using Aspose.Slides.Export;
namespace TestSlides
{
public class OdpToPdf
{
public static void ConvertOdpToPdf()
{
String path = @"/Users/KnowledgeBase/TestData/";
// Initialize a license to convert ODP to PDF
Aspose.Slides.License licenseOdpExport= new Aspose.Slides.License();
licenseOdpExport.SetLicense(path + "Conholdate.Total.Product.Family.lic");
// Instantiate the Presentation class object to access to ODP file
Presentation presPPT = new Presentation(path + "Sample.odp");
// Instantiate the PdfOptions class object
PdfOptions pdfFileOptions = new PdfOptions();
// Define the output PDF file options
pdfFileOptions.JpegQuality = 90;
pdfFileOptions.EmbedFullFonts = true;
pdfFileOptions.SaveMetafilesAsPng = true;
pdfFileOptions.TextCompression = PdfTextCompression.Flate;
// Convert the ODP to PDF
presPPT.Save(path+ "PowerPoint-to-PDF.pdf", SaveFormat.Pdf, pdfFileOptions);
}
}
}

为了开发 ODP 到 PDF 转换器,基于 C# 的 API 已得到有效使用。可选的 PdfOptions 类用于通过操作不同的属性(包括 AccessPermissions、Compliance、DefaultRegularFont、JpegQuality、ImageTransparentColor、ShowHiddenSlides 以及设置输出 PDF 密码等)来进一步自定义输出 PDF 文件。

本文重点介绍如何使用简单的 API 调用使用 C# 将 ODP 保存为 PDF。如果您有兴趣了解将演示文稿转换为 Markdown 文件的过程,请参阅有关 如何使用 C# 将 PPTX 转换为 Markdown 的文章。

 简体中文