Edit PDF via Python

Advanced PDF Editor for Python for .NET. Use Aspose.PDF to modify PDF documents programmatically

How to Edit PDF with Python

Do you need to edit PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With Python libraries like Aspose.PDF, developers can edit text in PDF, insert graphs using external data, modify tables and more. These libraries are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional Python developers.

  • Edit PDF elements: tables, texts, images,, fields, etc.
  • Edit PDF formatting attributes and styles
  • Add new elements
  • Work with graphs and forms

In order to edit PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for python-net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

How to Edit PDF via Python


You need Aspose.PDF for Python to try the code in your environment.

  1. Design and Develop your editor.
  2. Or use Aspose Editor by accessing its demo app using advanced WYSIWYG editor.
  3. Upload PDF files to edit.
  4. Modify the document with relevant changes.
  5. Save the PDF file.

One of the most requested features is the editing and adding text in PDF. Working with text is very convenient with Python library: edit text, update text and format text using Python. The following example demostrates how to modify a PDF document in Python:

Edit PDF Files - Python

This sample code shows how to edit text in PDF - Python

	import aspose.pdf as ap

    # load PDF file
    pdf = ap.Document('input_file')
    # instantiate TextFragment Absorber object
    text_fragment_absorber_address = ap.text.TextFragmentAbsorber()
    # search text within page bound
    text_fragment_absorber_address.text_search_options.limit_to_page_bounds = True
    # specify the page region for TextSearch Options
    text_fragment_absorber_address.text_search_options.rectangle = ap.Rectangle(100, 100, 200, 200, True)
    # search text from first page of PDF file
    pdf.pages[1].accept(text_fragment_absorber_address)
    # iterate through individual TextFragment
    for tf in text_fragment_absorber_address.text_fragments:
        # update text to blank characters
        tf.text = ""
    # save updated PDF file after text replace
    pdf.save('output_file')

About Aspose.PDF for Python API

Aspose.PDF for Python via .NET API supports most established PDF standards and PDF specifications. It allows developers to insert tables, graphs, images, hyperlinks, custom fonts - and more - into PDF documents. Moreover, it is also possible to compress PDF documents. Aspose.PDF for Python via .NET provides excellent security features to develop secure PDF documents. Some of the key features of Aspose.PDF for Python via .NET API include:

  • Ability to read & export PDF in multiple image formats including BMP, GIF, JPEG & PNG.
  • Set basic information (e.g. author, creator) of the PDF document.
  • Conversion Features: Convert PDF to Word, Excel, and PowerPoint. Convert PDF to Images formats. Convert PDF file to HTML format and vice versa. Convert PDF to EPUB, Text, XPS, etc.

You can find more information about Aspose.PDF for Python via .NET API on our documentation on how to use API.