Skip to main content

pdfpipe-python

Official Python SDK for PDFPipe. Turn HTML or a URL into a PDF with one call, backed by a real browser engine.

pip install pdfpipe-python

Quick start

from pdfpipe import PDFPipe

pdfpipe = PDFPipe(api_key="pp_live_...")

# From HTML
pdf = pdfpipe.from_html("<h1>Invoice #4012</h1>", {"format": "A4"})
with open("invoice.pdf", "wb") as f:
    f.write(pdf)

# From a URL
pdf = pdfpipe.from_url("https://example.com")
with open("example.pdf", "wb") as f:
    f.write(pdf)

Get an API key at pdfpipe.xyz. Keys look like pp_live_....

API

PDFPipe(api_key, base_url="https://api.pdfpipe.xyz", session=None)

from_html(html, options=None) -> bytes

from_url(url, options=None) -> bytes

Both return the raw PDF bytes. options is a dict, all keys optional:

Key Values Default
format A4, A3, A5, Letter, Legal, Tabloid A4
landscape bool False
margin any CSS length 1cm
print_background bool True
scale 0.1 to 2.0 1.0
page_ranges e.g. "1-3, 5" all pages
prefer_css_page_size bool False
media print, screen print
timeout_ms 1000 to 60000 30000
wait_until load, domcontentloaded, networkidle0, networkidle2 networkidle0
wait_for CSS selector none
wait_ms up to 5000 0
header_html HTML string none
footer_html HTML string none
tabular_nums bool False
deduplicate_images bool False
pdf_a bool False

Running headers and footers

header_html and footer_html render on every page. Five class names are substituted per page as the document is laid out:

Class Becomes
.pageNumber the current page number
.totalPages the total page count
.date the render date
.title the document title
.url the source URL, when rendering from a URL
pdf = pdfpipe.from_html(
    html,
    {
        "header_html": '<div style="font-size:9px;width:100%;text-align:center">Q3 Report</div>',
        "footer_html": '<div style="font-size:9px;width:100%;text-align:center">'
                       'Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>',
    },
)

Inline your styles. The header and footer are laid out separately from the page body, so a stylesheet in your HTML does not reach them, and they inherit a very small default font size.

If you leave margin at its 1cm default, the top or bottom margin widens to 2cm automatically so the header or footer has room. Set margin yourself if you want different spacing.

The other three

tabular_nums forces font-variant-numeric: tabular-nums, so digits share one width. Use it whenever a column of numbers has to line up, which is most invoices and statements.

deduplicate_images merges identical image XObjects after rendering. It only pays off when the same image repeats across pages, a logo in a running header being the usual case, and it costs a little post-processing time.

pdf_a writes PDF/A-1b XMP metadata on a best-effort basis. It marks the file for archival tooling but does not guarantee full conformance, which would also require tagged structure and an embedded ICC profile.

Errors

Non-2xx responses raise PDFPipeError with a .status attribute and a clear message.

from pdfpipe import PDFPipe, PDFPipeError

try:
    pdf = pdfpipe.from_url("https://example.com", {"timeout_ms": 45000})
except PDFPipeError as e:
    print(e.status, str(e))

License

MIT

Download files

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

Source Distribution

pdfpipe_python-0.2.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

pdfpipe_python-0.2.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pdfpipe_python-0.2.2.tar.gz.

File metadata

  • Download URL: pdfpipe_python-0.2.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for pdfpipe_python-0.2.2.tar.gz
Algorithm Hash digest
SHA256 1330634d5a372a8842510a742d5d20a728ec227e6b5ba283f9a9c2ab46962abf
MD5 aac0a016354e73fddc2b5d1218166422
BLAKE2b-256 0fda179ac4cc0e6b6542c73a461252bc40bc915bebe42bbcfedf9b7e9e4cf05b

See more details on using hashes here.

File details

Details for the file pdfpipe_python-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pdfpipe_python-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for pdfpipe_python-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 922db65fe305a90139dd08d5326a539deb05cf2a09f29fdd1412c8860f0ab37a
MD5 03896f01ee195c00ae74c57c5f0a1052
BLAKE2b-256 c25baf2e9ddc0db2ef12cd8d6c21861e06984180baa462c1c346935913b17cd8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page