PDFDocumentCreate

Resumen

Creates a new PDFDocument object in memory.

Debate

A common scenario for using this function is the creation of a PDF map book. The steps typically involve creating a new PDFDocument object, appending content from existing PDF files, and saving the PDFDocument object to disk.

A file will not be created until you either appendPages or insertPages to the PDFDocument object and execute saveAndClose.

Sintaxis

PDFDocumentCreate (pdf_path)
ParámetroExplicaciónTipo de datos
pdf_path

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

String
Valor de retorno
Tipo de datosExplicación
PDFDocument

The PDFDocument object allows for the management of PDF documents, including facilities for merging and deleting pages, setting document open behavior, and creating or changing document security settings.

Muestra de código

PDFDocumentCreate example

This script will create a new PDF document, append the contents of three separate PDF documents, and save the resulting PDF file.

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