Skip to main content

Paged HTML rendering library

Project description

build docs license downloads pypi pyver

PlutoPrint

PlutoPrint is a lightweight and easy-to-use Python library for generating high-quality PDFs and images directly from HTML or XML content. It is based on PlutoBook’s robust rendering engine and provides a simple API to convert your HTML into crisp PDF documents or vibrant image files. This makes it ideal for reports, invoices, or visual snapshots.

Invoices

Tickets

Invoices

Tickets

Installation

pip install plutoprint

PlutoPrint requires PlutoBook. On Windows (win_amd64), Linux (manylinux_2_28_x86_64) and macOS (macosx_14_0_arm64), prebuilt binaries are bundled with the package and no further steps are necessary. On other architectures or when building from source, see the Getting Started guide for dependency setup and build instructions.

On macOS and Linux, you can also install PlutoPrint using Homebrew:

brew update
brew install plutoprint

Quick Usage

Generate a PDF from the command line with the installed plutoprint script:

plutoprint input.html output.pdf --size=A4

Generate PDF with Python

import plutoprint

book = plutoprint.Book(plutoprint.PAGE_SIZE_A4)
book.load_url("hello.html")

# Export the entire document to PDF
book.write_to_pdf("hello.pdf")

# Export pages 2 to 15 (inclusive) in order
book.write_to_pdf("hello-range.pdf", 2, 15, 1)

# Export pages 15 to 2 (inclusive) in reverse order
book.write_to_pdf("hello-reverse.pdf", 15, 2, -1)

# Render pages manually with PDFCanvas (in reverse order)
with plutoprint.PDFCanvas("hello-canvas.pdf", book.get_page_size()) as canvas:
   canvas.scale(plutoprint.UNITS_PX, plutoprint.UNITS_PX)
   for page_index in range(book.get_page_count() - 1, -1, -1):
      canvas.set_size(book.get_page_size_at(page_index))
      book.render_page(canvas, page_index)
      canvas.show_page()

Generate PNG with Python

import plutoprint
import math

book = plutoprint.Book(media=plutoprint.MEDIA_TYPE_SCREEN)
book.load_html("<b>Hello World</b>", user_style="body { text-align: center }")

# Outputs an image at the document’s natural size
book.write_to_png("hello.png")

# Outputs a 320px wide image with auto-scaled height
book.write_to_png("hello-width.png", width=320)

# Outputs a 240px tall image with auto-scaled width
book.write_to_png("hello-height.png", height=240)

# Outputs an 800×200 pixels image (may stretch/squish content)
book.write_to_png("hello-fixed.png", 800, 200)

# Get the natural document size
width = math.ceil(book.get_document_width())
height = math.ceil(book.get_document_height())

# Outputs a high-resolution 5x scaled image
book.write_to_png("hello-scaled.png", width * 5, height * 5)

# Render manually on a canvas with white background
with plutoprint.ImageCanvas(width, height) as canvas:
   canvas.clear_surface(1, 1, 1)
   book.render_document(canvas)
   canvas.write_to_png("hello-canvas.png")

Generate QR Codes

Quick example of using -pluto-qrcode(<string>[, <color>]) to create QR codes with optional colors.

import plutoprint

HTML_CONTENT = """
<table>
  <tr>
    <th class="email">Email</th>
    <th class="tel">Tel</th>
  </tr>
  <tr>
    <th class="website">Website</th>
    <th class="github">GitHub</th>
  </tr>
</table>
"""

USER_STYLE = """
body {
  margin: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f7f7f7;
  font: 16px Arial;
}

table {
  border-spacing: 2rem;
  background: #fff;
  padding: 2rem;
  border: 1px solid #ccc;
  border-radius: 16px;
}

th::before {
  display: block;
  width: 130px;
  height: 130px;
  margin: 0 auto 0.8rem;
}

.email::before   { content: -pluto-qrcode('mailto:contact@example.com', #16a34a); }
.tel::before     { content: -pluto-qrcode('tel:+1234567890', #2563eb); }
.website::before { content: -pluto-qrcode('https://example.com', #ef4444); }
.github::before  { content: -pluto-qrcode('https://github.com/plutoprint', #f59e0b); }
"""

book = plutoprint.Book(plutoprint.PAGE_SIZE_LETTER.landscape())
book.load_html(HTML_CONTENT, USER_STYLE)
book.write_to_png("qrcard.png")
book.write_to_pdf("qrcard.pdf")

Expected output:

QR card

Generate Charts with Matplotlib

import plutoprint

import matplotlib.pyplot as plt
import urllib.parse
import io

class CustomResourceFetcher(plutoprint.ResourceFetcher):
   def fetch_url(self, url):
      if not url.startswith('chart:'):
         return super().fetch_url(url)
      values = [float(v) for v in urllib.parse.unquote(url[6:]).split(',')]
      labels = [chr(65 + i) for i in range(len(values))]

      plt.bar(labels, values)
      plt.title('Bar Chart')
      plt.xlabel('Labels')
      plt.ylabel('Values')

      buffer = io.BytesIO()
      plt.savefig(buffer, format='svg', transparent=True)

      return plutoprint.ResourceData(buffer.getvalue(), "image/svg+xml", "utf-8")

book = plutoprint.Book(plutoprint.PAGE_SIZE_A4.landscape(), plutoprint.PAGE_MARGINS_NONE)

book.custom_resource_fetcher = CustomResourceFetcher()

HTML_CONTENT = """
<body>
  <img src='chart:23,45,12,36,28,50'>
  <img src='chart:5,15,25,35,45'>
  <img src='chart:50,40,30,20,10'>
  <img src='chart:10,20,30,40,50,60,70'>
</body>
"""

USER_STYLE = """
body {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  background: #f7f7f7;
  height: 100vh;
  margin: 0;
}

img {
  background: #fff;
  border: 1px solid #ccc;
  margin: auto;
  max-height: 45vh;
}
"""

book.load_html(HTML_CONTENT, USER_STYLE)
book.write_to_png("charts.png")
book.write_to_pdf("charts.pdf")

Expected output:

Charts

Samples

Invoices
Invoice 1 Invoice 2 Invoice 3
Tickets
Ticket 1 Ticket 2
Ticket 3 Ticket 4

Support and Contribution

This project continues to grow through the encouragement and involvement of its users. If it has been helpful to you or your team, here are a few meaningful ways you can support its future:

  • Give it a Star on GitHub. Starring the project helps others discover it and shows your appreciation for the work behind it.

  • Sponsor the project to help drive new features, improve stability, and ensure the project continues to evolve for everyone who relies on it.

  • Share your feedback. If you have suggestions, feature requests, or notice an issue, please open a GitHub issue. Your voice and experience help guide the project’s direction.

Star History Chart

License

PlutoPrint is licensed under the MIT License, allowing for both personal and commercial use.

Project details


Download files

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

Source Distribution

plutoprint-0.19.0.tar.gz (41.1 kB view details)

Uploaded Source

Built Distributions

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

plutoprint-0.19.0-cp314-cp314-win_amd64.whl (19.9 MB view details)

Uploaded CPython 3.14Windows x86-64

plutoprint-0.19.0-cp314-cp314-manylinux_2_28_x86_64.whl (21.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

plutoprint-0.19.0-cp314-cp314-macosx_14_0_arm64.whl (19.0 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

plutoprint-0.19.0-cp313-cp313-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.13Windows x86-64

plutoprint-0.19.0-cp313-cp313-manylinux_2_28_x86_64.whl (21.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

plutoprint-0.19.0-cp313-cp313-macosx_14_0_arm64.whl (19.0 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

plutoprint-0.19.0-cp312-cp312-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.12Windows x86-64

plutoprint-0.19.0-cp312-cp312-manylinux_2_28_x86_64.whl (21.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

plutoprint-0.19.0-cp312-cp312-macosx_14_0_arm64.whl (19.0 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

plutoprint-0.19.0-cp311-cp311-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.11Windows x86-64

plutoprint-0.19.0-cp311-cp311-manylinux_2_28_x86_64.whl (21.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

plutoprint-0.19.0-cp311-cp311-macosx_14_0_arm64.whl (19.0 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

plutoprint-0.19.0-cp310-cp310-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.10Windows x86-64

plutoprint-0.19.0-cp310-cp310-manylinux_2_28_x86_64.whl (21.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

plutoprint-0.19.0-cp310-cp310-macosx_14_0_arm64.whl (19.0 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file plutoprint-0.19.0.tar.gz.

File metadata

  • Download URL: plutoprint-0.19.0.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for plutoprint-0.19.0.tar.gz
Algorithm Hash digest
SHA256 55f3c6724f0dc217d28218ced1aacc23f7f87bf2b7e6682152eb9f80eb4e3d3c
MD5 306f51ea0bedf90f8b6a93aa6c49cb24
BLAKE2b-256 cf53156600a9b55da259e419025fa8d08e7253b64e6af5923d53bf3bb6f41ca4

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0.tar.gz:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 82932d26a7ec36da2ee21f18e417f7435aea0e69a7276086bd512f57ee002c73
MD5 08018ac8d790ed1c20f31fdee272fc69
BLAKE2b-256 2d258ff33dcaa381d09097615fc7eaeae90c73760e6a11d8db8ce218b5b1e2b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp314-cp314-win_amd64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c920a09e9ff6854e9f8274723fd03186327d98ebe7f3350694cef946cc5461a7
MD5 45d3277af02f12b3443def2a8c033df3
BLAKE2b-256 cce7dd7a5523e38ce36c0eaab116e892b0a878fa8a7ed1298fd58b8299d11374

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bac65483890daa9d2823de085724553279e7b82f3538f4dfa80268344bfc0f1e
MD5 1121420a6b9e754c8ac69df71218acb6
BLAKE2b-256 54d3380356bd2afcf13296402d73bf4c6878e77a8f4e36f3bf089863a333530f

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp314-cp314-macosx_14_0_arm64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 82a564c179793743d8b84d1cae019242f25b124156c7810211d143f5da53fc5b
MD5 dbdf8dbb2bb76ffd9ef8aa1708ad9c7d
BLAKE2b-256 885524a757f844a3bb5260e1f570e2998d4f98ffce3b9da7a0cb143c6a10089b

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp313-cp313-win_amd64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3eab98d6093a03bf393f311f499f58b141d504f93097f550eb4cf53a389893d5
MD5 9a84b207d2b47743d27d7d0f9b5376e8
BLAKE2b-256 cda023e76b55cb416ad4a954a1f6c430a2a1b0e5490aeb0e92ba63e4e184b652

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e094b74e828048b78264c0ffeb09f297b5bf240edb034afb396c8557bbe73ea8
MD5 15b8be4c088445d76afa718d40a7d1d0
BLAKE2b-256 5e945ca2a05c71cd8c8e450e0bc32bc3ee08a1bb0a14ca327083861771da4e8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 07822c8d64453bf7ae619c737163ebe86b63e8aba49c859c4b99a0d9003dcbcc
MD5 a2946f606021e6cdb2dd4d26aedbf32c
BLAKE2b-256 8f322fc46463dad891713d9dc5decb2d6fe4f965fbabcd150f4bdc3785b48ffb

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp312-cp312-win_amd64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5b3dd2bfd388e8ac0b519cb4e033989e39b3fb9ef55ab5e2d23072de9742083
MD5 c4ebde9a18e16d372711125278eb6bce
BLAKE2b-256 e5f038799f92a5629532d969b67f3cb6c883d5849aed74000388f0da3fd295b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9bddc104803322bad25fef16404bae691f59156efdc23060b63bcf7bc1736304
MD5 2a0507321a26b61a64de70802d6c0ef9
BLAKE2b-256 65ecd16e4d58f12b82d63d1f2956b0073802ef753fbc0ebbb0656a72c8d0df4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9ea1aee4b1b8c0c29dd70a9d117268399d8ff2b95cac7ca1ddb48b8481b29ae9
MD5 387e69bb90e4057d7a3801f0b2c21f39
BLAKE2b-256 9358e7fbd7bd9e4db611e7978879ff9ec07f5da6e2e45a6d2e37326acfbd73bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp311-cp311-win_amd64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 562ed60c94ff22678366b5d13c2d944f317e9ff02ef4169046bb47404693d105
MD5 d64490a49c24e9454cde610863fa4793
BLAKE2b-256 34c35f64a794e763d1c6b16fce938826c4d88053e3e92e86de9d6953eaffaa5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1c4e088fcf02b3b70397afbed61b26a9fe37aa3d6e5349c16cba7e55d2a4b942
MD5 ec99999d4687b18872a7f5cb830811b8
BLAKE2b-256 744d23dcf6d341cf935741f0438349e43044ed46a1ec9c5991c3674baf22631b

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 555606a763aafa872776cd028f337b74d1e1f06fa291e3d0e05b2fe797586e20
MD5 722bef7f2cb4993a82b482e1b3511394
BLAKE2b-256 23a0e44d98e7b966a377ca718bfde9687317bc7d2846099531a8481cde6646de

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp310-cp310-win_amd64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b094db7374f29e0c17652e17c714df6ffcc238c00ac64011db40901cba8f78a
MD5 ec1c91ae3267983899e187cf07454a36
BLAKE2b-256 275442889178d0fb8c6702728fdd7fef07493a058bd183175edf79bb7db94a99

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: main.yml on plutoprint/plutoprint

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

File details

Details for the file plutoprint-0.19.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.19.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9e46ed5980e38dbf559e9002bf28833e17ed1c94d3d6c39934a15c10923c2373
MD5 e63893afb0773dc1852176836144c541
BLAKE2b-256 f642150785a2e76a8e2352caedf9e80873bc4d8bb5ba285f1927c541591f6aad

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.19.0-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: main.yml on plutoprint/plutoprint

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