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

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

plutoprint-0.11.0-cp313-cp313-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

plutoprint-0.11.0-cp312-cp312-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

plutoprint-0.11.0-cp311-cp311-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

plutoprint-0.11.0-cp310-cp310-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.10Windows x86-64

plutoprint-0.11.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.11.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.11.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.11.0.tar.gz
Algorithm Hash digest
SHA256 f6290e0c473bdc810cb5457503157f90a7c0f9399b8fa3147cea7fed93455395
MD5 c4f1e24ddd6409d682aa9d429ee9941e
BLAKE2b-256 249dc611a24fb16258437f2b2908e10011f8cb975a992ef20a3cb0d98a250dc8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 20822aa2cec2fb2aee82e1252e1f0a046c777f504f1b511296394725e7754bb1
MD5 ee07e304c9863bfed0f1ba833bd6f193
BLAKE2b-256 3d62d3b6f7ec95197267dda81ae3dd612cb56a5e934d1e6eac6622c075e3eb1b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 90c434778021326726dd8af84a4b837116c6bd9955ec7c9b775566e64a8188e4
MD5 fa544209e8e55378a8a046858cd55bf2
BLAKE2b-256 79a01c6b446dd21fe7e5f78f91d0468e1efa3b90e6dde6c6d828d09743f1c8eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dd6a82378750d7d30f56aed320f0f29794f485905159600f70098274d7426d63
MD5 9080957f957f6e780401e24479bd13c1
BLAKE2b-256 db499cf6a4e9b30cd6e5cc233995a3f5b4a7e40fabed73e8ced755b4adc6edb3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6c17085f86608613afc1c5eb5527e963aaf987a2d91308c156bbaab9be70ce85
MD5 0311f69f99f662120dcddb238b64431d
BLAKE2b-256 0994623b167426a6a4dff22f39d71220343565f1c90d2d19d48a6fe2b84a8ff1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7ff1201993bf1313e8171834798d4e6a13efbe96ce9c601393165fd3b57b816e
MD5 b9c1aebc9982534458913abaa1eeca72
BLAKE2b-256 ebbcaeea713554f877a7918574782b03c37228c770c59224db0d5907b219c6bd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aa04ddf95d44d6d09827601430faa3c1f685587416b2d7c885b7cde530c567b8
MD5 d5373b39157bb9194e52ca5f0f4fbf43
BLAKE2b-256 447e6fcc5b50796acdb5a4453fa4d3ff3763ad99aa83d631515dfbb2f862cd4e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f8b58f81b6f5dc7421444052081ef328d9e32c80486a91d466258b3b36ef9000
MD5 9131740a7e5d9b39b886dd97c98f85e0
BLAKE2b-256 f0612b71858b56e845c8d7dded6007160ab7a37b293d4506a1b9ef2834b8b2e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0db6daa27a71f0fca5c7a4ffc28f041b10776d44db566742be7144e1537864fe
MD5 862729eeff12115d415525e39ca5b145
BLAKE2b-256 3defd0e07e129760290e5a8b2b443b0739c0f23022661a6a68017561fe4854ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9f77806506eff4c33605d50e31702956319da6c90fd6932116c086c1197cd7ba
MD5 5b9e5e05ce2c53bc221fa6c3ccf12e5e
BLAKE2b-256 abbfa1962525a01b36681bf153801b479e4542d8cf91a1c58eef36df217a0af9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 89a2f0eefcbb19d9e532a16ee79c6ed59f9f99a72f160e86f0f8051f507d915f
MD5 ce84700ca33dd2fa2cd64798eace5f88
BLAKE2b-256 1a50b9afd960d675c9b4562f68e004f4b99ffa96f32e843c7444de12be8748cc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 614c868db1bfba6347f495b2e4b388c5f8505369b7c7da34cc69f7a845755207
MD5 ef1887ff4334c2ca5a5143433a9a6f46
BLAKE2b-256 18f8aacb5a53930bea30ad3c72b2721b1d31ff60990da51dde19d2c77accbd7b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 052532d4fec59ddeea7e82ed163fa88f8c8d713bdd3ee7170665c46421b80620
MD5 f7a84cae139c2a711e881565351b2ff7
BLAKE2b-256 25f00b693e3ac24e8127099d18983a3003e6c38a0ab6004fc92c546a53242e69

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 46aa9c8c6dfdb713a571ce030b936b67605c78ca86df8c01083fcc1b2ef099ee
MD5 93600c0cd54a1fccd8e578bf0a85247e
BLAKE2b-256 4e706658ca7752113b75d5e89d65a9bc272e993b1f2e46a2708d589c7a0f9e0e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5ded9a40b395d69c8298fd7e88810493b2b756948a60b9363eb548863820d5a6
MD5 cdb4c2ebd33ca505e0a08d75f0b16da4
BLAKE2b-256 2f73dea596ded51ec402c332dcb628fd41b872de9e7775cd691804c910a41289

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.11.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4ab121300127efc16d7fdc6b1ab7cd3981e0206d13253aefab4717b469402ea7
MD5 1023814de62fa670c682a6cf575225cb
BLAKE2b-256 d010e45e0d765633dd8d84e063b55344332945cb993bfd46eb0e8509573adafc

See more details on using hashes here.

Provenance

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