本主题介绍如何更改 PDF 设置以使用 Python 在 Adobe 中打开。它分享了设置应用程序开发环境的信息、编程步骤列表以及展示如何使用 Python 更改 PDF 查看首选项的示例代码。您将学习设置各种属性以在 Adobe 中打开 PDF 文件时设置不同的 UI 元素。
使用 Python 更改 PDF 打开设置的步骤
- 建立使用 通过.NET 为 Python 提供 Aspose.PDF 更改查看偏好的环境
- 加载要更改打开设置的源 PDF 文件
- 使用 Document 类中的属性来更改默认打开设置
- Save 更改 PDF 在 Adobe 中的打开方式后的输出 PDF 文件
以上步骤总结了如何使用 Python 更改打开 PDF 文件的默认设置。首先,将源 PDF 文件加载到 Document 对象中,并设置与 PDF 打开设置相关的属性。根据需要将具有自定义打开设置的生成的 PDF 文件保存在磁盘或流中。
使用 Python 更改 Adobe 中打开 PDF 的设置的代码
import aspose.pdf as pdf | |
import io | |
# Load License | |
license = pdf.License() | |
license.set_license("License.lic") | |
pdfDocument = pdf.Document("test.pdf") | |
pdfDocument.center_window = True | |
pdfDocument.direction = pdf.Direction.R2L | |
pdfDocument.display_doc_title = True | |
pdfDocument.fit_window = True | |
pdfDocument.hide_menubar = True | |
pdfDocument.hide_tool_bar = True | |
pdfDocument.hide_window_ui = True | |
pdfDocument.non_full_screen_page_mode = pdf.PageMode.USE_OC | |
pdfDocument.page_layout = pdf.PageLayout.TWO_COLUMN_LEFT | |
pdfDocument.page_mode = pdf.PageMode.USE_THUMBS | |
pdfDocument.save("output.pdf") | |
print("Viewing Preferences changed successfully") |
此代码示例演示了如何更改使用 Python 打开 PDF 的设置。您可以将一些布尔标志设置为 true 或 false,例如在中心打开 PDF、在标题中显示文档名称、隐藏菜单栏以及隐藏工具栏以列出一些内容。您可以使用枚举器来设置其他属性,例如 Direction 枚举器用于设置并行打开时的页面方向、PageMode 用于设置退出全屏模式时的模式以及 PageLayout 用于相应的设置。
本文教我们如何设置打开 PDF 文件的查看偏好。如果您想将 PDF 文件扁平化,请参阅 如何在 Python 中压平 PDF 上的文章。