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, 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

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.10.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.10.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.10.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.10.0.tar.gz
Algorithm Hash digest
SHA256 802671eb74521ae97690f25cfb5038ed25db67cfafa12b0b9725f117df651dc9
MD5 418f99ff36ff7edcc07c71fcf44672ad
BLAKE2b-256 462d7467cfaa2206eb3acf69adec70f1b51da6f406ac7ac0d5703dd34bcb1374

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e8e6c0afb898c7dec8e6b5eaf52d6f47fb73878c669406219b0cb74a4cd1233c
MD5 58e2674b2191932f7dbc01bf8d24f27a
BLAKE2b-256 4ebf6f8b053cc72aaf53d4d9a5cc5208011808a474c61c3367e6deeae6e5b96c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 400f1a05de360e149a0897497871527e335093b691d26ce9da3bdcd5d6c5369f
MD5 2cb11e14b97075377f29e40e0ecd02b8
BLAKE2b-256 63bfb98ce023951266e5dcaa0ec92048fda190f7d39d0cedbfcf3aeff45e2bea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e3da93aac0d7c660dd9b807a15b75766b7c1891900657836d21977c6e08e7210
MD5 6836bdad733f018e7a298f84fb46543f
BLAKE2b-256 e116df9de13c8b9d5a19998205bba78f4d011c245536588bb6dbd33dd4684836

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e2632b5d054af60a0b5d3cd9bb3af5821d165003db1bd8dd7af8ebcfeb26adb5
MD5 49ebf74a87dec223c9a5baaf556c7911
BLAKE2b-256 0d76bbce2092978b0af7d8d9650a185e68e887910fe4ac8c3387b0f0eb94547c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 87db3e51b1aa0c91a6eb718c12cad3c28be2529edc0fcc22e6ab123b4468cf4d
MD5 c628b6404ed798e6d197fec1fb9eadee
BLAKE2b-256 12fb35c19395d5525547a8edec490e2cf68d4b0e604318049b8c6c60cb0b0eeb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 405907a53bd2386c4a7447c6b9158114f9fff12d36c16d03d7a648fb0a36a4e7
MD5 d68078c2520c20ab9d825e45b825c034
BLAKE2b-256 7db4813562433e59e41c5e34e7195474d6fa000dd46884562cf99c58d20e0a40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c700ebad9b32a1325858f27f627847d5693898e613a74173a5bda78b104cd7e3
MD5 5bf41303d8ff643b6c10c9e8e1e2df8d
BLAKE2b-256 b74086984c44af2de357713cd98de3fee67220e3384c0d13fe503feb677fe14c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 56fdb01548799110b04efbe1859b1542a9d9daaf1bc5de5950d5d20ddd449bb8
MD5 89534fbc3fb03e50c0eeaf4d7b9a404e
BLAKE2b-256 4bd7f4fb41d88aebcb384a39082a8b567c4dc0fea7abc0afcff07f589ba51621

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e079ff1ca5bcc7bcdf0a18e4004b927c5b6cd3438c4c94ce1ea6dd5c1abb7a08
MD5 9e319eea703c094f0ebf25c1ea83cae9
BLAKE2b-256 5bf498690b816abb956106666cd7d8563dacf6eb6a5e8b38c9a2962620896deb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 60abd4f0d96080585e46263cc5a3a097661cd0f5278910dcbced16fcf9eb73e5
MD5 71316d6e60527381c47d4117b8f2cfc3
BLAKE2b-256 de2d9686cb4ff3ee3cda93feeebacf1b27115870f2cbe87e3b01bd72816aa990

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3168a64beaf813d2b3521bf0b20d7a10f9e4a74516d83aaac65a66320643442d
MD5 3795a6b0ba073345acf382e9270913a5
BLAKE2b-256 8e8f9589e850a004d5f6c0e525621705bc192ffd442cd86f324dd56b2352480d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ac0cb1976f0186782f101eae362625c516a057ff915e600b7681da600490e730
MD5 7dabc20e257cbc3c19c938925fff99a2
BLAKE2b-256 903a0e220c0bc6e8d1d2ab5495faccdf04a13d026d4c432accba287eae64dce0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 45dbf9aa80314651f622a2559103876e3a65f9df8974a75e8121058318708b9f
MD5 5d287228a4ffd55047ac94f754c7ae22
BLAKE2b-256 02d72b9f6160a88e0759a4e1ffbc2eb6d69be0ffbc80fec65e1443c7dfdb2de1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 401199c1c508e9f918d2a031ace085f973c2f7f5a1ce302f1d8f3fa0c0eab5d1
MD5 6a12e7074fb991afff6d8b40bff14e1e
BLAKE2b-256 811d1889749eea8118e7483fecd958a4446cd1cf0bab7849e838779dd1e126bc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.10.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5062929d6d610003112799e412e22383eb5150fee4c95954eaae4b4aee57e1c2
MD5 db4ae37e1cfeeea4ca84706cd2a35201
BLAKE2b-256 1057c3cbc7457b644181562d77b16ad2c81ea1e84b3b10e14b1f94bfc35f9847

See more details on using hashes here.

Provenance

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