在 Python 中将 ODP 转换为 PDF

这篇简短的文章重点介绍了如何在 Python 中将 ODP 转换为 PDF。它还表示建立开发环境所需的步骤以及编程任务列表,以及使用简单的 API 接口在 Python 中将 ODP 转换为 PDF 的示例代码。该应用程序可在 macOS、Windows 和 Linux 内的任何 Python 和 .NET 配置环境中使用。

使用 Python 将 ODP 保存为 PDF 的步骤

  1. 建立环境,使用Aspose.Slides for Python via .NET使用Python将ODP导出为PDF
  2. 使用 Presentation 类对象访问源 ODP 演示文稿,将 ODP 转换为 PDF 文件
  3. 使用 PdfOptions 类对象并设置所需的 PDF 文件选项
  4. 将 ODP 文件以 PDF 形式保存在磁盘上

通过执行上述步骤,我们可以使用 Python* 将 ODP 快速导出为 PDF。该过程首先从磁盘或内存流访问示例 ODP 文件,然后使用 PdfOptions 类的实例来设置所需的输出 PDF 文件属性。最后,加载的ODP将使用save方法以PDF文件的形式保存在磁盘上。

使用 Python 将 ODP 导出为 PDF 的代码

import aspose.slides as slides
# The path to source files directory
filepath = "C://Words//"
#Load the license in your application to
#convert the ODP presentation to PDF
odpToPdfLicense = slides.License()
odpToPdfLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic")
# Create the Presentation object to load the source presentation file
odpPre = slides.Presentation(filepath + "Sample.odp")
# Initialize the PdfOptions class
pdfOpts = slides.export.PdfOptions()
pdfOpts.jpeg_quality = 90
pdfOpts.embed_full_fonts = True
pdfOpts.save_metafiles_as_png = True
pdfOpts.text_compression = slides.export.PdfTextCompression.FLATE
# Save the loaded ODP to a PDF file
odpPre.save(filepath + "OdpToPdf.pdf", slides.export.SaveFormat.PDF, pdfOpts)

上面的例子表明,开发一个基于Python*的ODP到PDF转换器的API可以很容易地参考。您可以通过设置 PdfOptions 类公开的不同属性(包括 access_permissions、jpeg_quality、image_transparent_color、compliance、default_regular_font、show_hidden_slides)以及设置输出 PDF 文件密码等来进一步自定义输出 PDF 文件。

本文教我们如何使用 Python* 使用简单的 API 接口*将 ODP 保存为 PDF。如果您想了解如何将演示文稿转换为 Markdown 文件,请参阅有关 如何使用 Python 将 PPTX 转换为 Markdown 的文章。

 简体中文