pdfrw Library

0.4 · maintenance · verified Thu Apr 09

pdfrw is a pure Python library for reading and writing PDF files. It's designed for efficiency, offering capabilities for operations such as subsetting, merging, rotating, and modifying PDF metadata. The current version, 0.4, primarily focused on enhancing Python 3 compatibility and proper Unicode support. While still functional, its release cadence has been sporadic, and some sources suggest development has ceased.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to read an existing PDF file and write its contents to a new PDF file, effectively creating a copy. It also includes a basic step to create a dummy `input.pdf` for a runnable example.

from pdfrw import PdfReader, PdfWriter, PageMerge

# Create a dummy input PDF for the example
# In a real scenario, 'input.pdf' would already exist.
writer = PdfWriter()
writer.addpages([PageMerge().add_text("Hello World").render()])
writer.write("input.pdf")

# Read an existing PDF
reader = PdfReader("input.pdf")

# Create a new PdfWriter object
writer = PdfWriter()

# Add all pages from the reader to the writer
writer.addpages(reader.pages)

# Write the content to a new PDF file (e.g., creating a copy)
writer.write("output_copy.pdf")

print("PDF 'input.pdf' read and copied to 'output_copy.pdf'")

view raw JSON →