pypdfsuit
Python bindings for gopdfsuit - a comprehensive PDF library for generation, merging, splitting, form filling, HTML to PDF/Image conversion, compression, and redaction.
Features
- PDF Generation: Create PDFs from structured templates with tables, images, and styled text
- PDF Merging: Combine multiple PDFs into a single document
- PDF Splitting: Split PDFs by pages, ranges, or maximum pages per file
- Form Filling: Fill PDF forms using XFDF data
- HTML to PDF: Convert HTML content or URLs to PDF documents (pure-Go, no browser needed)
- HTML to Image: Convert HTML content or URLs to images (PNG, JPG)
- PDF Compression: Compress PDFs with Light/Medium/Heavy tiers, no Ghostscript needed
- PDF Redaction: Securely redact sensitive information using coordinates or text search
Installation
From Source
- Build the shared library locally:
cd bindings/python
chmod +x build.sh
./build.sh
On Windows, use the batch file instead:
cd bindings\python
build.bat
- Install the Python package:
pip install .
Windows Note
There is currently an issue on Windows. Please build the application locally.
Sample data for the Python bindings is available here:
Requirements
- Python 3.8+
- Go 1.26.4+ (for building the shared library)
- No browser or Ghostscript needed - HTML conversion is pure-Go via gowkhtmltopdf
Quick Start
Generate a PDF
from pypdfsuit.builder import TemplateBuilder, Font
b = TemplateBuilder("A4", True)
b.add_title("My Document", font="Helvetica", size=24, bold=True)
tb = b.add_table(2, 1.0, 1.0)
tb.add_row(
Font("Helvetica").size(12).bold().cell("Name"),
Font("Helvetica").size(12).cell("John Doe"),
)
pdf_bytes = b.generate()
with open("output.pdf", "wb") as f:
f.write(pdf_bytes)
Prefer raw templates? generate_pdf also accepts a hand-built PDFTemplate
(low-level; the builder above is preferred):
from pypdfsuit import generate_pdf, PDFTemplate, Config, Title
from pypdfsuit.builder import make_props
template = PDFTemplate(
config=Config(page="A4", page_alignment=1),
title=Title(
props=make_props("Helvetica", 24, bold=True, align="center", borders=(0, 0, 0, 0)),
text="My Document"
),
elements=[]
)
pdf_bytes = generate_pdf(template)
Merge PDFs
from pypdfsuit import merge_pdfs
with open("doc1.pdf", "rb") as f1, open("doc2.pdf", "rb") as f2:
merged = merge_pdfs([f1.read(), f2.read()])
with open("merged.pdf", "wb") as f:
f.write(merged)
Split a PDF
from pypdfsuit import split_pdf, SplitSpec
with open("document.pdf", "rb") as f:
pdf_data = f.read()
# Split specific pages
spec = SplitSpec(pages=[1, 3, 5])
parts = split_pdf(pdf_data, spec)
# Or split every 5 pages
spec = SplitSpec(max_per_file=5)
parts = split_pdf(pdf_data, spec)
for i, part in enumerate(parts):
with open(f"part_{i+1}.pdf", "wb") as f:
f.write(part)
Convert HTML to PDF
from pypdfsuit import convert_html_to_pdf, HtmlToPDFRequest
# Convert HTML string
request = HtmlToPDFRequest(
html="<html><body><h1>Hello World</h1></body></html>",
page_size="A4",
orientation="Portrait",
)
pdf_bytes = convert_html_to_pdf(request)
# Or convert a URL
request = HtmlToPDFRequest(
url="https://example.com",
page_size="Letter",
)
pdf_bytes = convert_html_to_pdf(request)
Fill a PDF Form
from pypdfsuit import fill_pdf_with_xfdf
with open("form.pdf", "rb") as f:
pdf_data = f.read()
with open("data.xfdf", "rb") as f:
xfdf_data = f.read()
filled = fill_pdf_with_xfdf(pdf_data, xfdf_data)
with open("filled.pdf", "wb") as f:
f.write(filled)
Redact a PDF
from pypdfsuit import apply_redactions_advanced
with open("document.pdf", "rb") as f:
pdf_data = f.read()
redacted = apply_redactions_advanced(pdf_data, {
"blocks": [
{"pageNum": 1, "x": 120, "y": 620, "width": 180, "height": 24}
],
"textSearch": [
{"text": "Confidential"}
],
"mode": "visual_allowed"
})
with open("redacted.pdf", "wb") as f:
f.write(redacted)
API Reference
Types
PDFTemplate- Main template structure for PDF generationConfig- Page configuration (size, orientation, security, etc.)Title- Document title sectionTable,Row,Cell- Table structureElement- Generic element (table, spacer, image)Image,Spacer- Additional elementsSecurityConfig- Encryption settingsPDFAConfig- PDF/A compliance settingsSignatureConfig- Digital signature settingsHtmlToPDFRequest- HTML to PDF conversion optionsHtmlToImageRequest- HTML to image conversion optionsSplitSpec- PDF split specificationFontInfo- Font information
Functions
generate_pdf(template: PDFTemplate) -> bytesget_available_fonts() -> List[FontInfo]merge_pdfs(pdf_files: List[bytes]) -> bytessplit_pdf(pdf_data: bytes, spec: SplitSpec) -> List[bytes]parse_page_spec(spec: str, total_pages: int = 0) -> List[int]fill_pdf_with_xfdf(pdf_data: bytes, xfdf_data: bytes) -> bytesconvert_html_to_pdf(request: HtmlToPDFRequest) -> bytesconvert_html_to_image(request: HtmlToImageRequest) -> bytesget_page_info(pdf_data: bytes) -> dictextract_text_positions(pdf_data: bytes, page_num: int) -> list[dict]find_text_occurrences(pdf_data: bytes, text: str) -> list[dict]apply_redactions(pdf_data: bytes, redactions: list[dict]) -> bytesapply_redactions_advanced(pdf_data: bytes, options: dict) -> bytes
Props String Format
Cells and titles carry a props string:
FontName:FontSize:StyleCode:Alignment:BorderLeft:BorderRight:BorderTop:BorderBottom
- FontName: Helvetica, Courier, Times-Roman, etc.
- FontSize: Integer size in points
- StyleCode: 3 digits for bold(1/0), italic(1/0), underline(1/0). e.g., "100" = bold only
- Alignment: left, center, right
- Borders: 1 = border, 0 = no border
Example: "Helvetica:12:100:center:1:1:1:1" = Helvetica 12pt, bold, centered, all borders
You rarely need to hand-write these: the fluent builder spells the same string.
from pypdfsuit.builder import Font, make_props
Font("Helvetica").size(12).bold().center().bordered().cell("Name")
# same bytes as Cell(props="Helvetica:12:100:center:1:1:1:1", text="Name")
make_props("Helvetica", 12, bold=True, align="center", borders=(1, 1, 1, 1))
License
MIT License - see LICENSE for details.
Metadata
Release files for pypdfsuit 7.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypdfsuit-7.0.1.tar.gz | 15.5 MB | Without provenance | Details for pypdfsuit-7.0.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypdfsuit-7.0.1-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details for pypdfsuit-7.0.1-cp312-cp312-win_amd64.whl |
| pypdfsuit-7.0.1-cp312-cp312-macosx_26_0_universal2.whl | CPython 3.12 | CPython 3.12 | macOS 26.0+ universal2 (ARM64, x86-64) | Details for pypdfsuit-7.0.1-cp312-cp312-macosx_26_0_universal2.whl |
Total release size: 38.9 MB
Release files / pypdfsuit-7.0.1.tar.gz
| Download URL | pypdfsuit-7.0.1.tar.gz |
|---|---|
| Size | 15.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad832bd7572b68b1ac8179208479756aeb5a7872c4ebb816b5951dfeaf0211b9
|
|
BLAKE2b-256 checksum How to use checksums |
d03b4bcd5f53de460c306cfca4e26bc230b41e76ec6c9d08bfdd134f83ef900b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pypdfsuit-7.0.1-cp312-cp312-win_amd64.whl
| Download URL | pypdfsuit-7.0.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 15.3 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
777011e9c1b0223b8b51886cff5dd8865af8c4fd583b8970fe17556e9944c4c7
|
|
BLAKE2b-256 checksum How to use checksums |
254cf0af558204635625ca9802eaad4d69396c39e435fba612d54f630bf9c073
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pypdfsuit-7.0.1-cp312-cp312-macosx_26_0_universal2.whl
| Download URL | pypdfsuit-7.0.1-cp312-cp312-macosx_26_0_universal2.whl |
|---|---|
| Size | 8.2 MB |
| Tags | CPython 3.12 macOS 26.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
03481d15112aa17144fed8529afea253c6f13f4c42ada033f3292d35840101b5
|
|
BLAKE2b-256 checksum How to use checksums |
9ddfb94909de295dc16ce9ecf029d4216017059dc1a2f83eecdc29aab31eeb36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for pypdfsuit 7.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.