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.15.0.tar.gz (52.2 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.15.0-cp314-cp314-win_amd64.whl (19.9 MB view details)

Uploaded CPython 3.14Windows x86-64

plutoprint-0.15.0-cp314-cp314-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

plutoprint-0.15.0-cp314-cp314-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.15.0-cp313-cp313-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

plutoprint-0.15.0-cp313-cp313-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.15.0-cp312-cp312-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

plutoprint-0.15.0-cp312-cp312-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.15.0-cp311-cp311-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

plutoprint-0.15.0-cp311-cp311-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.15.0-cp310-cp310-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

plutoprint-0.15.0-cp310-cp310-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for plutoprint-0.15.0.tar.gz
Algorithm Hash digest
SHA256 3d6118898ebe655fdd6ffe68dc936982ec3c8249c878934b98b6d3aa3278228b
MD5 9e9ee10274fafbf3265f1810a4e5f870
BLAKE2b-256 26bf0566e5907ae8b8427fce93c66a71d8b8a0394bb525a635cafc9d703c03ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 44342fc5b517b008f72b1a6d9c6a398277ed9db3c664b0c4367d3fe809f7eaa6
MD5 cb7c5ffcd49d963c322332334e03367d
BLAKE2b-256 13ab4c3f491baf70375dc3c7d46d9005b53e9ea08daed63c5d22847d98e752eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 98501f520991066c2ab523112b92f693c6616fc5c06caca8ecd7ce8571e231f5
MD5 8724065df13f8eecaf82e185a4d5040b
BLAKE2b-256 e62f2ec53ea20fe522841cf40aa3b0588dd713e03d0c8b82cb428f857d0e40b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bcb67e09cb24a924364aa56e4294be7139232f2456eb4f06baf826f678398ac3
MD5 38094e17a3f4b0a72fb3ea6014d59289
BLAKE2b-256 3f1a86e4b291e599c2c5e4f2f7aaac63ee62fb2eb38071e74ad262c6c310c591

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c6a727c91e53c24303eb170d6530c78539d6b76bee5fc052c08d1a778b58f024
MD5 a855c6a1e28b23f2c02f982866483bde
BLAKE2b-256 bed6d6cced9dafe1dda1987010bf49b55460cae818a032324a9d2591ca29cfcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad8e46365e093c8241d11db25364168d76de229370dfec1fb193ee78f0b1b413
MD5 f237cbaee10a65a206473063f1909fd0
BLAKE2b-256 2b714828784ae54549ac2dd313570f19d3adeaf93a0960ff3cb5c4ebf7d4098f

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8210e115f9ee012aceab0085735e0b6badfde9b457fbe1228997aff5bf0c2bba
MD5 33a6a65bbb2499341d85e35f2b05df01
BLAKE2b-256 31083ae9ac8534e03b6f53c9f23cdd8b01293b7b0f0f2a8a9b6f9519b14b009c

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 eaae5201eb44d1a9090105af7cecc84eeb9f39391d38549ca978c22f68d68f0b
MD5 9b8609e16a078e9a551ca8d94bd22de9
BLAKE2b-256 6dc72e09f52e08aef32402be9c6911881b30fac921688777d1018bb35d5192d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4fd8143b612ebbfd69c97e48c995ae32c1a7b62c41d85da25f6be93c0c81fe30
MD5 e967b6760fb7caef5b73073acfb80bb8
BLAKE2b-256 7c870f746036d6c0b25d9350f90734da1dcf32757707a9dc324978c98c378870

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 109539bc4cde5e907c063125bef3d8b2a207adbc9d78eec5698c9f0b7fcf36b5
MD5 31caae9a5a53c3a300034b049b13f3cc
BLAKE2b-256 358c066caa9dd9e52c96089283f16a85bd5de64b6ce88cb98857f647df0ba15e

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d17b0e199079622f1568c4ef252ac4b02ad3a8d105c5b4890fbe34d29c845833
MD5 5888bae0a77e220e572f6a84fc307e7e
BLAKE2b-256 65dfbb3e6294c1b5b228667cdcd3001ffdc499cf6d15f1e8d4b3888f38800a07

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48f32ed74b5d84a1ca00e8d714ad00a53cfe67ea0161b1d3f1d467be02091f43
MD5 9cdf61fb1663d750db19d522d2e01587
BLAKE2b-256 331949ec535c19e20ea629189629d226d7ecc40b38eaadf65c3a0edc8d087a21

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4e4084fc15037e5d92e575fb0daba393ba9cfefe55795ebe94406222044b7743
MD5 ec9595e65824a88b113084e31fe86fb2
BLAKE2b-256 71bf8cee83cff217928f6f630e3597532ff1515e77e55687007f775b422c01fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 efffd32ce7a441987fd7c7572724e618ebc6762b88ac66c90b84efe7895d70c4
MD5 50a38dba79340ff07e1e8d89a7697b1b
BLAKE2b-256 cd7109d34539cd7b89e24f79572cbd0817cb070cbeaebae410fc6ecf4b1e64ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0925b8b275df65d65ac0124e30d5b6185d59cfe11186211d32b3fa3d0381a11b
MD5 933845127ce141638d4d87fc1e11d17b
BLAKE2b-256 dc192d286e9420db0c22c20fd1f10659714b96a168e04b5e266e87006355519d

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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.15.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for plutoprint-0.15.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 59a0872dcf1339a7c795df60f93a66f5a584ed988668bfaed2d223dc649185a5
MD5 4631c6ed3957feacded7e66fab454def
BLAKE2b-256 61554b9d591955c07e21c50c771cc6dbac6f6cf9903ea75a040c3b88eadda216

See more details on using hashes here.

Provenance

The following attestation bundles were made for plutoprint-0.15.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