PDFDocumentCreate

摘要

在内存中创建新 PDFDocument 对象。

说明

使用此函数的常见情况是创建 PDF 地图册。一般步骤包括创建新 PDFDocument 对象、从现有 PDF 文件附加内容以及将 PDFDocument 对象保存到磁盘。

在对 PDFDocument 对象执行 appendPagesinsertPages 之后执行 saveAndClose 才会创建文件。

语法

PDFDocumentCreate (pdf_path)
参数说明数据类型
pdf_path

调用 saveAndClose 方法时,用于指定生成的 PDF 文件的路径和文件名的字符串。

String
返回值
数据类型说明
PDFDocument

PDFDocument 对象可用于管理 PDF 文档,包括合并和删除页面的工具、设置文档打开方式的工具以及创建或更改文档安全性设置的工具。

代码示例

PDFDocumentCreate 示例

此脚本将创建新 PDF 文档、附加来自三个独立 PDF 文档的内容并保存生成的 PDF 文件。

import arcpy, os

#Set file name and remove if it already exists
pdfPath = r"C:\Projects\YosemiteNP\AttractionsMapBook.pdf"
if os.path.exists(pdfPath):
    os.remove(pdfPath)

#Create the file and append pages
pdfDoc = arcpy.mp.PDFDocumentCreate(pdfPath)
pdfDoc.appendPages(r"C:\Projects\YosemiteNP\Title.pdf")
pdfDoc.appendPages(r"C:\Projects\YosemiteNP\MapPages.pdf")
pdfDoc.appendPages(r"C:\Projects\YosemiteNP\ContactInfo.pdf")

#Commit changes and delete variable reference
pdfDoc.saveAndClose()
del pdfDoc