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.21.0.tar.gz (41.5 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.21.0-cp314-cp314-win_amd64.whl (20.0 MB view details)

Uploaded CPython 3.14Windows x86-64

plutoprint-0.21.0-cp314-cp314-manylinux_2_28_x86_64.whl (21.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

plutoprint-0.21.0-cp314-cp314-macosx_14_0_arm64.whl (19.1 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

plutoprint-0.21.0-cp313-cp313-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.13Windows x86-64

plutoprint-0.21.0-cp313-cp313-manylinux_2_28_x86_64.whl (21.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

plutoprint-0.21.0-cp313-cp313-macosx_14_0_arm64.whl (19.1 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

plutoprint-0.21.0-cp312-cp312-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.12Windows x86-64

plutoprint-0.21.0-cp312-cp312-manylinux_2_28_x86_64.whl (21.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

plutoprint-0.21.0-cp312-cp312-macosx_14_0_arm64.whl (19.1 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

plutoprint-0.21.0-cp311-cp311-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.11Windows x86-64

plutoprint-0.21.0-cp311-cp311-manylinux_2_28_x86_64.whl (21.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

plutoprint-0.21.0-cp311-cp311-macosx_14_0_arm64.whl (19.1 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

plutoprint-0.21.0-cp310-cp310-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.10Windows x86-64

plutoprint-0.21.0-cp310-cp310-manylinux_2_28_x86_64.whl (21.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

plutoprint-0.21.0-cp310-cp310-macosx_14_0_arm64.whl (19.1 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for plutoprint-0.21.0.tar.gz
Algorithm Hash digest
SHA256 699c90f4d452b3e151184ca0ac707ddd04c29f29a8bb6f38a163559199e642bf
MD5 d4090db0c89ec465d764e0d0d0dad88f
BLAKE2b-256 16e0930e488122538d514698b65dcaf443f88ce9e66af0727d5ae6a1c7bb7223

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.21.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 20.0 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plutoprint-0.21.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ba98bd71a64d7af216ab8ead8315db815873f37fef7f52dec6bb4f8b9925f5d2
MD5 5a568d71ab61fb2c4543889fe55db626
BLAKE2b-256 0134565c6187a030537c9ff18e2d50e31830b9953aad35fa42fed1ddc3f1433d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0ded380361d5f8b9c629b128869f22cac5da386317ebe79be9360555d445f99a
MD5 e1bb03dd7864fdba6749d6f838f666c1
BLAKE2b-256 649c5025d0c37cf43d84adabf2b0e9032bedcbb193b733a302f42722f220bf0c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7aa26b865afc0ace1b573365edca96b598c99a661104821e2777e3da97130d3a
MD5 981a9189baeffb19db25bbe6c8aa4d24
BLAKE2b-256 40e464c7da074007fc61a271b159fd8493d2a536e2352dbb20b012b592c2ea3f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.21.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 19.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plutoprint-0.21.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d37e76f20bc162eb9e49a7630052a8ec6b2cfd3d26fdd0da59c2d7a2d75430ad
MD5 037abef5694623e3ba773ffaca006d8f
BLAKE2b-256 face275832edfd7bc26562e20545e374ced5af6b2fe1f98ac993375983d139dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2edcff1f0b5d50b49604f7a95c415aa3032772ec5fd83358a0febc76450a3b92
MD5 28c1546af62385c3755e8655b8b1c782
BLAKE2b-256 684b671d58563f3fb86690d073b7498bb914b1d01941161e59fe1b2d0206f706

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 912180d6c5cc0e9d83d6a04fcf64e5eb99fd01f0818c58c4856a3a824d61184d
MD5 2e020a36f8d6a5ce07524d6abee447cd
BLAKE2b-256 64913e245031d5bde46078fc82fcc09605172e3774923a5e976e6e9dae3f215e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.21.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 19.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plutoprint-0.21.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c68ebbb9001732f820c06275eedd022ff55deab343e074affbdd659f141a4a12
MD5 8a1165cf49a878388d1350d6fade9d43
BLAKE2b-256 13aa96c08ae0ee912a5330633628d7d76147024012c86fabaf7d73d3184c8419

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0f19e8cce8d923e6db73fc0108d701cf2e996ebc87dd2327e7af01b4363c786c
MD5 89a4426d97c6d4182ca392d27eeca928
BLAKE2b-256 61c4559fd5682555636ea26921e094eb6d2290d4ba753c92b58c6490be34d26d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a921bdf8ed6a4855930b455c152ca3cfd007c8f3546c52dda698e6c5b97faa45
MD5 5f7690b5dae06cbf71b6843bff7328ea
BLAKE2b-256 4d64fdf4dd21e1537a4961e21138e712326784e612869519d2f613d16dfb4b37

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.21.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 19.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plutoprint-0.21.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 22b6c2adc8f11a5a1eebc33ab019df034ecd09d152c78afb4970bf5559488f9a
MD5 5f2e71408f56ebac819f23c7afd3c8be
BLAKE2b-256 3f88a9b2eabfc60ecfaf02da52517be49fd2c2cfac9f3e49d95fc35c71726f18

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6aee9352dbc6b58838688eaae9880b2cf808fc0d1e447d96757cee2ce5a28e27
MD5 196acf6c50e4edc965ff50460cb19b57
BLAKE2b-256 3a12538554c29b403b239d888f7be5b273b036b2f885bc1a1dccbf9635473e61

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 078d7dce0b77a9a6464347ee6727d51704caa401d976f79041950a02515c2291
MD5 1262d5fefe073d6700bac72d52ad094b
BLAKE2b-256 2761fc1f374e65a170d44ca3330bec8af8c43082960504fe3b2eeb18c18112ea

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.21.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 19.3 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plutoprint-0.21.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a41821fa089f98aaf7dcf79923d0bd59ced9981199891b9cf66a6bef50c78529
MD5 856cf2675226aedee55b77e6f3c6a854
BLAKE2b-256 def7f084f723bfd7270a26d17dabbea52728fa6deb2769e10f0dad62b6effcac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 521bacc63d30c6279fd631ff8cc259d8184b81b24395f406be34e6f765980df2
MD5 56f2fa092a81899ea2ec222501875cce
BLAKE2b-256 b838ee7e3b9dc44f50308ba03ac328b9852ed0ca44f432a03bbf4d80bbfe96ee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.21.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9495b63945f374aa3c20e7e394ee5c0767b9f821af3080650da9ac9f27a1faa8
MD5 ce52bf1ef8619ed3c3398ecbff2ee6ca
BLAKE2b-256 63aefca48fa1b8f93d267d44c902e3bac4fc2b2d74eb90eae548849807672cea

See more details on using hashes here.

Provenance

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