This short tutorial guides on how to remove pages from PDF using Python. You will get detailed information about the environment settings, a list of tasks to be performed for developing the application, and a runnable sample code to remove pages from PDF file using Python. Different overloads of the delete() method will also be discussed using very few numbers of API calls.
Steps to Delete PDF Pages using Python
- Set the environment to use Aspose.PDF for Python via .NET to remove pages
- Instantiate the PdfFileEditor class object for deleting pages
- Create an array of integers to set the page numbers that are to be deleted from the PDF
- Call the delete() method by passing source PDF, list of page numbers, and output PDF
These simple steps summarize the process to delete some pages from PDF using Python. The process is commenced by instantiating an object of the PdfFileEditor class object that supports deleting the pages from a PDF. An array of integers is required that contains any page numbers within the range of available pages for providing an argument to the delete() method.
Code to Remove Pages from PDF Document using Python
This code demonstrates the process to delete pages from PDF document using Python. There are two different overloaded methods available that can be used to delete pages from an existing PDF in the form of a physical file present on the disk or a stream containing the input PDF file and create a PDF stream where desired pages are eliminated from it.
This article has shared the sample code to remove some pages from PDF using Python. If you want to learn the process to move pages in a PDF file, refer to the article on how to move pages in PDF using Python.