PDFDocumentCreate (arcpy.mapping)

摘要

在内存中创建空的 PDFDocument 对象。

讨论

PDFDocumentCreate 函数接收路径以确定新创建的 PDF 文件的保存位置和文件名。尽管如此,如果不对 PDF 文件执行插入或追加页面以及保存等后续操作,仍不能生成 PDF 文件。PDFDocumentCreate 将返回脚本应执行和保存的 PDFDocument 对象。使用此函数的常见情况是创建 PDF 地图册。这些步骤通常包括从地图文档导出一定数量的独立 PDF 文件、创建新的 PDFDocument 对象、从已导出的 PDF 文件和其他文档追加内容以及保存最终的 PDF 地图册。

请注意,既不可能创建空白 PDF 文件,PDFDocumentCreate 函数也不可能将任何空白页添加到文档内容中。要使 saveAndClose 方法能够成功创建文件,必须使用 appendPagesinsertPages 方法将内容添加到 PDFDocument 对象中。

有关如何创建地图册的详细说明,请参阅使用 ArcGIS 构建地图册帮助主题。

语法

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

A string that specifies the path and file name for the resulting PDF file when the saveAndClose method is called.

String

代码实例

PDFDocumentCreate 示例

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

import arcpy, os

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

#Create the file and append pages
pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)
pdfDoc.appendPages(r"C:\Project\Title.pdf")
pdfDoc.appendPages(r"C:\Project\ParcelAtlas.pdf")
pdfDoc.appendPages(r"C:\Project\ContactInfo.pdf")

#Commit changes and delete variable reference
pdfDoc.saveAndClose()
del pdfDoc
9/15/2013