Append Pages to PDF
Contents
[
Hide
]
Combining pages from different PDF documents is a common requirement in document processing workflows. Using Aspose.PDF for Python, developers can easily append pages from one or more PDF files to an existing document.
This code snippet shows how to use the append method of the PdfFileEditor class to add selected pages from another PDF file to the end of a source PDF. By specifying the page range, developers can control exactly which pages are included in the final document.
- Create a PdfFileEditor Object.
- Append Pages from Another PDF.
The specified pages from the secondary PDF document are appended to the end of the original PDF, creating a combined output file.
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
# Append Pages to PDF
def append_pages_to_pdf(infile, sample_file, outfile):
# Create a PdfFileEditor object
pdf_editor = pdf_facades.PdfFileEditor()
# Append pages from the specified PDF document to the end of the source PDF document
pdf_editor.append(infile, [sample_file], 1, 2, outfile)