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

Uploaded CPython 3.14Windows x86-64

plutoprint-0.16.0-cp314-cp314-manylinux_2_28_x86_64.whl (20.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.16.0-cp313-cp313-manylinux_2_28_x86_64.whl (20.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.16.0-cp312-cp312-manylinux_2_28_x86_64.whl (20.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.16.0-cp311-cp311-manylinux_2_28_x86_64.whl (20.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.16.0-cp310-cp310-manylinux_2_28_x86_64.whl (20.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

plutoprint-0.16.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.16.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.16.0.tar.gz
Algorithm Hash digest
SHA256 098e5c244bd7a59697afc09d372707f2f98a89c6f23b76beb579a78648c9c354
MD5 9af62ae03036627d09cfea1d845e77ea
BLAKE2b-256 cd45fa851fbb1ccc0ccd60cec0decbd184c0264f96ac43c7b656986ed0474bb8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 5b44b4917961d1f49b4686fa452fb9a369e51fcd02871704db8309a1a99fffcc
MD5 f81a3a3d08dc76e4ac8445784626878d
BLAKE2b-256 4501857d9926fadf5728bf7d26f00f7500f2dc03f5af8090dab08db801c115d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b7f21c12edcfc846161fe55b3a35ba300f1944255d16e2cebcc7f7924b231f06
MD5 44ea3908b848eed121aae7de911bd1e9
BLAKE2b-256 bbf6d16208ef5453f32526e2bf26aa770a88d322226495d10be744149c07d6ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 215afbf1449dff2e74da5ac9542aa93dbfdce0c96e317702f2ee54ee1255019f
MD5 fb3fcafb97ef2ad2c43b0078596bbdc4
BLAKE2b-256 83c200935e8f8e204530303414fe8622d86bdded5176f6ce7bffcfbc0395296a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 433c5fe6efb11b36475d9704ca59cd68ad6a8d42d30ab40b01f790c2b0773969
MD5 ed68c25e9e63a65872543ea4e87fc251
BLAKE2b-256 1d7e0669d828c494b810e76e37c44d0200aa2d2052f239a0f07deebc62674577

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4aee3f3767a85aa45ac66e1eed8555911363bb6c0c6c0c6bbbc8cb8f57beb123
MD5 7c214b9c17c730934f8ceddd9ccb3de7
BLAKE2b-256 b21f76dfab85fbe459b7f12e0d49e06c23fbd58aeb362e31a100c467f33c01dc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f10181716596731f9739e003e054aca608251d062f3bb16d1e070077d700978e
MD5 e9c81154a111267fea52da71c87012ad
BLAKE2b-256 486d66216de541e28280267436ae90f0939bfc84223368cab92457a3a41ac540

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d1f535fe749821df3f7a229e38c12988ced9e13354f0c74e8ee25e5b400aee3d
MD5 f8eabc62defc6d8f149bc5e1263f9748
BLAKE2b-256 2833ecb273a5ac16b053855f6837e4fc8077a0c45c6405aca6bba1cb79abb567

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a251cff21e84a2aef3b54642116576ef88a0cdaa70450d3ef7e4f447cc8fda00
MD5 2d0f7b4a1c7ba5d7d08d4a6e322dee4f
BLAKE2b-256 3d1e260d80830b01e6d185bee5fb6efd1d3d050754e91e863348c808c053dbe9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 31ba7725f0ba642970f0556f297a7a9ecacbfd30ab3f2b5d2f885fcb63775aec
MD5 15cf6eb5087ab2b02ee1c03b0bccdb9e
BLAKE2b-256 014fd96047390c96b2335474c32c7304dc039442f29a4758bbc9d957a76bb698

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7743b637ba93ba760866e125bee0b3f9c88872287c9e0312b6c114e1b3c48580
MD5 ed2ef970b2af05f16bf71e909f0c3953
BLAKE2b-256 208b2621e0e2c03ad0c0e61837bc5e35d7a1b4c37e87db407cf4c14ce04b6cff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 967b87a4ca710cac0d748fad1f9db6651f9aafe10941c1e544e0a8ba0cc2cd25
MD5 eecdb4f8bf206d17e5f02d741dd10f9d
BLAKE2b-256 dcca1a7fe159e864e845e48ebea990de18dd763af1cb34bfab2c9e3f95a38a90

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 91e80addcb9f65aec8a4025ccd7820feda56fd847445ae3d2324964c0c474a81
MD5 44c6e7be84dbfc9eb2df957bda24fb0b
BLAKE2b-256 5d7203d13f6b6027f210732dd98c0cfee9b72fcc11e5ad52f0b5df54bb911024

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 16fec79dff51a4a858a24c52631aa870c9cbe16e4aaaed05ad1295faa3caf923
MD5 e11e9489c83a0d67ae4f32f0a86d9c32
BLAKE2b-256 37e74adac46a4f3294c46aba920440aa4cd82bcbd71b709ffcca34cbbcaf4ee9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7908c92f0eee90f7822927eac99751381c1228c121e6688e9dead5f6ff63269c
MD5 7872d6611076d9d7bcf92be0daa65684
BLAKE2b-256 b706a3a50376dc75649f854724fbd83389b600b188027aad24c4b8bbf703e5a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.16.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dd9d2ea50d270936246b4290417dfc149516d8cb7adc1c9f6f8212d3bede37f6
MD5 e3b6b1153e6dce2e8c14afda8cad596b
BLAKE2b-256 3fc4dd67f9939a1af859f3d52993253843fe487840ef36e1630140831a1bc0f1

See more details on using hashes here.

Provenance

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