1. Products
  2.   Aspose.PDF
  3.   Aspose.PDF FOSS for Python

Aspose.PDF FOSS for Python

Open-source Python library for creating, reading, editing, rendering, and validating PDF documents — MIT licensed with no runtime fees.

Aspose.PDF FOSS — Open Source Python PDF Library

Aspose.PDF FOSS for Python is an open-source library for creating, reading, editing, rendering, and validating PDF documents. Built for Python 3.11 and later, it ships type information and integrates into any Python project with a single pip install aspose-pdf-foss-for-python command. The project is currently in alpha, so APIs and feature coverage continue to evolve ahead of the first stable release.

The Document class is the central entry point, exposing pages, form, outlines, and tagged_content for structural editing alongside encrypt, decrypt, merge, optimize, and flatten operations. Text is added with Page.add_text() and extracted or searched with PdfExtractor and TextFragmentAbsorber, including phrase- and regex-based replacement and redaction. Pages render to PNG or TIFF raster images through Page.render() and Page.save_as_image(). Interactive AcroForm fields are created and filled through Form and Field, and documents can be checked or converted toward PDF/A and PDF/UA compliance with Document.validate_pdfa(), Document.convert_to_pdfa(), and Document.auto_tag().

Aspose.PDF FOSS for Python is released under the MIT license with no runtime fees or usage restrictions. The core package depends only on cryptography and asn1crypto, with optional extras for Pillow-based image support, Brotli-based WOFF2 decoding, and HarfBuzz-based complex text layout. For enterprise features and support, see Aspose.PDF for Python — Enterprise Product.

Document and Page Operations

  • Create, load, save, and merge PDFs through Document
  • Manage pages with the mutable PageCollection exposed as document.pages
  • Add positioned Standard-14 or embedded Unicode text with Page.add_text()
  • Place raw, JPEG, or PNG images on pages with Page.add_image()
  • Draw vector shapes with Page.draw_rectangle() and Page.draw_line()

Practical scenarios

  • Generate invoices, certificates, and reports programmatically
  • Batch-produce documents from a shared template
  • Assemble multi-page reports from generated sections
  • Build PDFs entirely in memory inside a web service

Text Extraction and Search

  • Extract all page text with PdfExtractor and get_text()
  • Iterate page-by-page text with has_next_page_text() and get_next_page_text()
  • Search exact phrases and regex patterns with TextFragmentAbsorber
  • Replace matched text with Document.replace_text()
  • Redact matched text with Document.redact_text(), optionally drawing an overlay bar

Practical scenarios

  • Build full-text search indexes over document archives
  • Redact personally identifiable information before sharing
  • Find-and-replace boilerplate copy across templated contracts
  • Audit incoming documents for sensitive terms

Page Rendering to Images

  • Render a page to a dependency-free RGB raster with Page.render()
  • Save rendered output as PNG or TIFF via Page.save_as_image()
  • Batch-render whole documents with Document.save_page_as_image()
  • Control resolution with the dpi parameter and edge quality with antialias
  • Read raw pixel data from the returned RasterizedPage

Practical scenarios

  • Generate page thumbnails for a document management library
  • Produce print-ready TIFF proofs from finished layouts
  • Build page-preview galleries for a document viewer
  • Convert legacy PDF archives into image-based viewing formats

Forms and Interactive Fields

  • Read and iterate AcroForm fields through Document.form
  • Create text fields with Form.add_text_field()
  • Create checkboxes and radio groups with Form.add_checkbox() and Form.add_radio_group()
  • Create list and combo boxes with Form.add_list_box() and Form.add_combo_box()
  • Set values by field name through Field.value, then flatten with Document.flatten()

Practical scenarios

  • Automate invoice and contract form filling pipelines
  • Pre-populate application templates before distribution
  • Archive filled forms as non-editable, static-content PDFs
  • Extract submitted field values for downstream processing

Security, Encryption, and Signatures

  • Encrypt documents with Document.encrypt() using user and owner passwords
  • Change or clear passwords with Document.change_passwords() and Document.decrypt()
  • Validate embedded digital signatures with PdfSignature.validate()
  • Bound untrusted input with configurable PdfLoadLimits
  • Inspect signer, trust, and revocation status through ValidationResult

Practical scenarios

  • Protect confidential reports with per-recipient passwords
  • Verify signed contracts before archival
  • Harden a PDF ingestion pipeline against malicious uploads
  • Enforce print and copy permission restrictions on distributed files

PDF/A and PDF/UA Compliance

  • Run heuristic PDF/A validation with Document.validate_pdfa()
  • Convert documents toward PDF/A with Document.convert_to_pdfa()
  • Run heuristic PDF/UA accessibility checks with Document.validate_pdfua()
  • Auto-tag existing page content into a structure tree with Document.auto_tag()
  • Inspect and edit the tag tree through Document.tagged_content

Practical scenarios

  • Prepare outgoing documents for long-term digital archiving
  • Screen incoming PDFs for accessibility gaps before publishing
  • Build compliance reports for regulated industries
  • Remediate legacy PDFs toward accessibility standards

Create a PDF and Add Text

Build a new PDF document and add positioned text to a page in a few lines.

from aspose_pdf import Document
with Document() as document:
    page = document.pages.add()
    page.add_text(
        "Hello from Aspose.PDF FOSS!",
        x=72,
        y=720,
        font_size=18,
    )
    document.save("hello.pdf")

Render a Page to an Image

Load an existing PDF and save its first page as a raster image at a configurable DPI.

from aspose_pdf import Document
with Document() as document:
    document.load_from("input.pdf")
    document.pages[0].save_as_image("page-1.png", dpi=144)

Extract Text from a PDF

Bind a document and pull all of its page text out with the extractor facade.

from aspose_pdf import PdfExtractor
with PdfExtractor() as extractor:
    extractor.bind_pdf("input.pdf")
    extractor.extract_text()
    print(extractor.get_text())

Merge PDF Files

Concatenate several PDF files into a single output document.

from aspose_pdf import PdfFileEditor
with PdfFileEditor() as editor:
    if not editor.concatenate(["part-1.pdf", "part-2.pdf"], "merged.pdf"):
        raise RuntimeError(editor.last_exception)
  

Support and Learning Resources