This topic describes how to insert page break in PDF using Python. It has the details to set the IDE, a list of steps, and a sample code for adding page break in PDF using Python. You will learn to add multiple page breaks with a single API call on different pages.
Steps to Add Page Break to PDF using Python
- Set the environment to use Aspose.PDF for Python via .NET for adding a page break
- Load the source PDF file into the Document object for inserting page break
- Create an empty PDF file to save the output
- Create an object of the PdfFileEditor class that supports adding page breaks
- Create an array of page break objects by seeing the page number and pixel position from the bottom
- Call the add_page_break() method to add the page break and saving in the destination PDF file
- Save the destination PDF file on the disk
The above steps explain how to insert a page break in a PDF document using Python. You may load the source PDF file, create an empty PDF file to save the output and create the PdfFileEditor object. Set the page numbers with the page break distance in pixels from the bottom of the page, create an array of the page breaks, and call add_page_break() to insert the list of page breaks in the destination PDF file.
Code to Add Page Break in PDF using Python
This sample code shows how to insert a page break in Adobe PDF using Python. The page breaks are inserted in the order of elements in the array, so each page break is added and saved in the output subsequently. The page index starts from 1; therefore, to add a page break on the first page, set page number 1 instead of 0.
This article has taught us the process for adding page breaks. If you want to remove pages from a PDF file, refer to the article on How to remove pages from PDF using Python.