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

Uploaded CPython 3.14Windows x86-64

plutoprint-0.13.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.13.0-cp314-cp314-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.13.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.13.0-cp313-cp313-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.13.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.13.0-cp312-cp312-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.13.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.13.0-cp311-cp311-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.13.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.13.0-cp310-cp310-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for plutoprint-0.13.0.tar.gz
Algorithm Hash digest
SHA256 02ec801a7cdee89085d050b274ad9c3366949c085909149a563d1acf383a57aa
MD5 93fe0ad29003ac2457e77eb31b7fda76
BLAKE2b-256 777f50144b12fceab37b5d5273d52466c31d27da49ca272b03ff3e20e98d3d00

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2d6d08c2b7267bf3d6b3f8c5009e8d14bbc3ec6c160d53f92d45b39ae789063e
MD5 dce9bc9db6272096c5285b6d3dc64cd5
BLAKE2b-256 5acb8cba3f5c9768cca585e6250f673c484e924e36f1ae00fde1a3dd1407bb07

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 924074e3cd44de07aec79345e7e0962ed90b5b34fa450fecba8017ebe7ca2884
MD5 bc5cd1242966504753b7785fc17370b8
BLAKE2b-256 42a88459ede79f666e80b952cb76835c57fed88db97bf46cff30df40bf8cd9c6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 56375685bb94227bb32b53ee4946f852705b2cc0288a97dbd698842e13169369
MD5 fb97e6ecdfcc11efca89effa4f876471
BLAKE2b-256 80a25ff8f5e123443934ed49750f5351c2767ef0a3682ec6786fb5d125e13434

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b9ce215cb613d583525490b0fd668eeda9c3256727bc5421fa2cdd259acdbe6c
MD5 1ef3dbad35169e6041edb4ba16ae164c
BLAKE2b-256 22b0259d9a4b571698c8fa325fde617af23c55b070a5bdfb5a37804758e75fdf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2185b27f46825443d0794a977ef3889cd26adaeecaafdd323482e3730ef213d2
MD5 611a4dfed5a8a90ba129e2fb7c2bf53b
BLAKE2b-256 5bb30716c0c8055aee8dea8e6c65c0023711f29b0baac15f1c89afc5f74c04c9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bba71a0a3ea96154fdc5a20de6c7157a0d4ccfb39a6bd21eba06089a7f800bc1
MD5 4de7c37d55aa02f3d348a0b9ac4935ae
BLAKE2b-256 157e9ebd3a947df84615929cf216052be78297724dfe8fc7dad38884c49c3352

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a58056ccb70c8cdd0961ba51294672762beeff119e3eb17d20a01e64dcc468c
MD5 78994cd3852c2d10bfbdd0df319bb9fb
BLAKE2b-256 a970fab12082d70f63f8c19ede10ca769f8236b9c584c7e9e6ea4f81297e08c5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cb2b0aeb0e4756e61df616f8137a7e94eeed2c95f3b9a55349c35698ebb5411d
MD5 e0303bce48b45ddf1440a51ca206fa8d
BLAKE2b-256 2177215073adb9bce4c5add6c69627d953a7512ce96181690a3eaee493603eec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9de3661b36d28f72ef1f8705d0a83d0b62c3ca4988d745acb4a77893c97232d6
MD5 72bf6888f2ba9dec199141c32ec29bc7
BLAKE2b-256 7c73c38980b4c52569384cfb7467ca9f7eaa34308674d0f857167e29495d7875

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9ceb0b034557e0da790aaa0eb7ad207476c557eeb6b99d41547bbff4d48adbdd
MD5 64afaa29245fbc233985907095bb67b8
BLAKE2b-256 693f343f21a064f5587351c8cbcace6e0af06436e5bcebfa5bfb6d2d796e9012

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a9e3dece66dc5daef9a88a25c731da4dce2eda5e4c33537e11f0f8cbd9f45fbf
MD5 3fd7e069e2fe613d4e24c5c60136302d
BLAKE2b-256 6ad7055d2e48479197d1927634bdc951bd7c311dd23f2df6ad4c454d09c0fa1d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ecf5b3e24ca3ea2ca313c88d91a7c1fa421f851f25ec7ec1560825073f6ce3df
MD5 45fde4d45f9e4046c3f2cba9020c1202
BLAKE2b-256 9002c17b6564d292a76a1767d76844c24af00c1861102d41725522190478eb49

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ba5564aa7dec0626696019098b252480c4a28f943b6b111d4fd5b52b9dcd49f4
MD5 587ac993a60c99c094bf17e55aa3a1a5
BLAKE2b-256 6a962cfb5b9448936e91d7b3262a7b3dbb4c1a1b5bca0e374f600a2a8359ab49

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2cc3ef1e2e730d3f18b3d4e4ba3782b60c53cc6fd57dff9600ba5c09d6ac93d7
MD5 bfba52c57f0600581bca5fe596848322
BLAKE2b-256 78ebf4b484980e38ff6acdc941eacf679f55a67f9f9d7345372c7ec9e380800c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4b1d87cd4d85fd31aeb8d2720abfe079a6fba90c0ef5a0383540c719be7d5771
MD5 6ccc0c07de814d85bc8e42ed4431a373
BLAKE2b-256 fae991d7673c0ed89353d9a136b72b1ca59445443ee4438d46d7d53ae40e3f84

See more details on using hashes here.

Provenance

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