PDFDocumentCreate

Synthèse

Creates a new PDFDocument object in memory.

Discussion

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.

Syntaxe

PDFDocumentCreate (pdf_path)
ParamètreExplicationType de données
pdf_path

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

String
Valeur renvoyée
Type de donnéesExplication
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.

Exemple de code

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