Skip to main content

High-fidelity HTML to PDF conversion using Chromium

Project description

printwell

High-fidelity HTML to PDF conversion using Chromium's rendering engine.

Installation

pip install printwell

Quick Start

from printwell import Converter, PdfOptions, PageSize

# Create a converter (reuse for multiple conversions)
converter = Converter()

# Simple conversion
result = converter.html_to_pdf("<h1>Hello, World!</h1>")
result.write_to_file("output.pdf")

# With options
result = converter.html_to_pdf(
    "<h1>Hello</h1><p>World</p>",
    pdf_options=PdfOptions(
        page_size=PageSize.Letter,
        print_background=True,
    ),
)

# Get PDF data as bytes
pdf_bytes = result.data()
print(f"Generated {result.page_count} pages, {len(pdf_bytes)} bytes")

Batch Processing

from printwell import ConverterPool

pool = ConverterPool(max_concurrent=4)
results = pool.convert_batch([
    "<h1>Document 1</h1>",
    "<h1>Document 2</h1>",
    "<h1>Document 3</h1>",
])

for i, result in enumerate(results):
    result.write_to_file(f"doc_{i}.pdf")

Features

  • Rendering: Full HTML5/CSS3 support via Chromium's Blink engine
  • Large Documents: Automatic chunking and parallel rendering for documents >50MB
  • Watermarks: Text and image overlays with positioning and opacity control
  • Bookmarks: Table of contents and navigation structure
  • Annotations: Highlights, sticky notes, and geometric shapes

API Reference

Converter

Main converter class. Create once, reuse for multiple conversions.

  • html_to_pdf(html, render_options=None, pdf_options=None) - Convert HTML to PDF
  • url_to_pdf(url, render_options=None, pdf_options=None) - Convert URL to PDF
  • info() - Get renderer information

PdfOptions

  • page_size - PageSize enum (A3, A4, A5, Letter, Legal, Tabloid)
  • margins - Margins object
  • orientation - Orientation enum (Portrait, Landscape)
  • print_background - Print background colors/images
  • scale - Scale factor (0.1 to 2.0)
  • metadata - PdfMetadata object

RenderOptions

  • base_url - Base URL for relative resources
  • user_stylesheets - Additional CSS stylesheets
  • viewport - Viewport configuration
  • resources - ResourceOptions for network control
  • fonts - Font configuration options
  • max_chunk_size - Max HTML size before chunking (default 50MB, 0 to disable)

Other Packages

Links

License

AGPL-3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

printwell-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl (23.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file printwell-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for printwell-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b7fc8499e48c27e4ba1918af673992eac2b92fe35796ebf2e03471b8a344ac6a
MD5 79e881fdf419d6a96b760b984f0a12d3
BLAKE2b-256 0ff200404d3e2b75410da97274c1e667ed7c72fe72fed4eb3af92ee8accf3ee7

See more details on using hashes here.

Provenance

The following attestation bundles were made for printwell-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release-please.yml on printwell-dev/core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page