Add Page Breaks in PDF

Contents
[ ]

Page breaks are useful when you need to split long PDF pages into multiple pages or control how content is distributed across a document. Using Aspose.PDF for Python, developers can insert page breaks at specific positions without manually editing the PDF.

This article shows how to use the ‘add_page_break’ method of the PdfFileEditor class to insert a page break at a defined vertical coordinate on a selected page. The method creates a new page and moves the content below the break point to that page.

  1. Create a PdfFileEditor Object.
  2. Define the Page Break Position.
  3. Insert the Page Break.
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


# Add Page Breaks in PDF
def add_page_breaks_in_pdf(infile, outfile):
    # Create a PdfFileEditor object
    pdf_editor = pdf_facades.PdfFileEditor()
    pdf_editor.add_page_break(
        infile,
        outfile,
        [
            pdf_facades.PdfFileEditor.PageBreak(1, 400),
        ],
    )