Python PDF SDK for Editing Existing PDFs
Target and modify existing PDF content from Python 3.10+. Use context-managed sessions, explicit layout modes, and operation diagnostics in scripts, automation jobs, and backend applications.
Working Example
Run the first edit and check the result
Download the public quick-start PDF as input.pdf. The example replaces one word on page one and rejects an unexpected result before saving.
Supported Operations
Use Python interfaces for text, layout, pages, and PDF objects
Text operations
Use literal or regular-expression selectors with replace, insert, delete, and style requests.
Read the operation guideLayout control
Select source-anchored placement, reflow with fallback, or required reflow for each request.
Read the operation guidePages and objects
Add, delete, and move pages; edit images, vector paths, AcroForms, and Form XObjects.
Read the operation guideFonts and output
Find or register fonts, validate diagnostics, then save to a path or retrieve PDF bytes.
Read the operation guideStructured Text Extraction
Extract semantic reading units from a document or page
Analyze the current session as classified text blocks with reading order, source-element provenance, page-space bounds, and relationships. Each call reflects the current session state.
Read the structured-text guideLayout and Diagnostics
Choose between anchored placement, reflow when possible, and required reflow
Select how replacement text should behave when its length changes: keep it anchored to the original position, reflow it when the document structure supports reflow, or require reflow and return an error when it cannot be applied.
source_anchored()retains the selected source position.reflow_when_supported()permits source-anchored fallback.require_reflow()reports an error for unsupported targets.
Framework Integration
Keep synchronous PDF work off the FastAPI event loop
The route reads the uploaded bytes, runs the synchronous client in FastAPI's thread pool, checks errors, and returns the edited PDF. Configure upload limits and authentication with FastAPI dependencies or middleware, and map failures with registered exception handlers.
See the FastAPI PDF workflow guide for the dedicated framework page.
Compatibility and Limits
Check text editability, reflow diagnostics, and output requirements
- PDFDancer is a synchronous hosted-service client. Move calls off an asynchronous framework event loop.
- Text selectors require editable PDF text; outlines, paths, page images, and unusual encodings may not match.
- A successful change count does not prove that reflow occurred. Inspect change diagnostics and rendered output.
- Registered fonts still need glyph coverage for every replacement character.
- Saving output does not certify PDF/A conformance or preserve an existing digital signature.
- Deleting selected text is an editing operation, not security redaction.
Python Resources
Continue from the quick start to the Python API
Questions
Python PDF SDK questions
Start Using PDFDancer Today
Get started in seconds with our free tier. No credit card required.
Want to evaluate first? Run the anonymous quick start.