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.12.0.tar.gz (37.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.12.0-cp314-cp314-win_amd64.whl (19.4 MB view details)

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

plutoprint-0.12.0-cp313-cp313-win_amd64.whl (18.7 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

plutoprint-0.12.0-cp312-cp312-win_amd64.whl (18.7 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

plutoprint-0.12.0-cp311-cp311-win_amd64.whl (18.7 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

plutoprint-0.12.0-cp310-cp310-win_amd64.whl (18.7 MB view details)

Uploaded CPython 3.10Windows x86-64

plutoprint-0.12.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.12.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.12.0.tar.gz.

File metadata

  • Download URL: plutoprint-0.12.0.tar.gz
  • Upload date:
  • Size: 37.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.12.0.tar.gz
Algorithm Hash digest
SHA256 cbca7d1f2bc1c61c14c3feb9ab16b54583cfaa350ec8266de879940494e7dbe1
MD5 a3eb036520acaddb9d8e9a411f1eac9b
BLAKE2b-256 efd0af1b23123d37d1f672dbf5d68cf33b1ad1e274936079d33118ae9e18ce47

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8581aed1d90f4242fde0e9f5550034dbad17f43c18e5187d75917a8e68476bf5
MD5 1a32b2a038928b7e4446e26d10922943
BLAKE2b-256 6c0ec71bed1f33a020b3f76319073c31662991dd64030cf12ee9cbb278ec978b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9f63bb8758a7f8a9ccf7386cf4f221343f14ef73504a8d4a38b2bc37645644f7
MD5 82c40f7e5a10476eb6260d778cc871b0
BLAKE2b-256 700c307e9731f045ab3d8a820327d1ee650f79d00819aa69dc7bc9def4389aa9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b578b98b77483c6886dfd12b656f02e7a89de6210fd29e1b8e9a05c8492cf36e
MD5 5fb27aafe1298dda8d7b9fa0eaba443a
BLAKE2b-256 86c19d8ad737ed66d729bdf24339ac8df31e48cbd4bb92e7c09ba74605ce8aca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b2851412a2146ec47b3382ecdb956c9609e85f4d5ba65058d4d0cd905d722f47
MD5 0689a466f827654113e3df4cbeb6f547
BLAKE2b-256 38b42b911e13c0f92cf31d25543754f5c4f9d532f6b06df95ed93c9d13d02608

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ea94d99d20c2cd77333e294309b017cf6e9c40cd5e629287e5c7d4750bc7f2d2
MD5 1322d0a961e7155fd6f6d7402625ba8a
BLAKE2b-256 d8139b7fa1b29c4c4346e3bfb8ac43632e7b4b5cee02cd68a4ea15b99aebc677

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 04b0080ae8ef6e4e6df064301d5362950015d8ba302f72fa99d44bbcecb880af
MD5 9aa65dac34fc399fb305a4822eee8241
BLAKE2b-256 3a520725f5fb91fa4ec308ab63c078542526f42de6c51fa0327cd779ec46482e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dc55d993e6187c282bcae75f46610d03394bfac5ff4f7529dea14689eeb87a90
MD5 d4830ddb7e0e08f6a6326fa165a6f05f
BLAKE2b-256 d986b2aca1845a695321e202887528529ae24a8252383ded9b59642d2fbf05fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 921779700e953415876b8080dbaeb9f09ef0b25f2755e3cac3e37f2207c17446
MD5 be4f32ce3597f07b5676e642845a9f35
BLAKE2b-256 250f2ef54153c3661bb3f6096178ad3def15eed3a4975d0d4552b7a53efaad88

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bdbcb34c8afc239d4fac734d265ed3b64196eeb9ecb60fccc817664c9b23cd44
MD5 5bb5c7c897638d6217780210fe0beb81
BLAKE2b-256 663fc3aa230606851509ef9f726f7ac0f208cd05546b868d7e70c8cb96c2b9a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f78c95efd6c4009df43840edc48769a6fc621c183714f76912da3bf778f56e5d
MD5 121816d5e48581370567a440f2388257
BLAKE2b-256 f0f3f8fc18e09409d22f125a9984e538cf9f54f65908706f0aaa4c0907cd8ca8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da3fece84fdd8812d7249b87aa3fd489bb0e0052dee459a00692c292617f12ab
MD5 82478a23518cf479b085a9d390214d47
BLAKE2b-256 82637b5f2d54f2a77c60a2879f0e46022fda55d400c673850cf46c86ca98d72f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0a245aaa8f20a7cbf07fa76da43179d5d99327fe320864b15270fd872c34d562
MD5 8c310318b60aa01dcd77ca123e0a2faa
BLAKE2b-256 dcdbba9116e66dc90385e7b74f05dd6014e33a9bc7d1906398fcc7ce890050eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6f026589c0d3757762811332d9b4dfcc232a34832c49a7cedc8c0237f1966599
MD5 a59307f2a1a80e6082afe54040fd076b
BLAKE2b-256 8aba20f8acdfe046fccb221771d1edbbbcfe86c89fc199c8a50c1d0d681c44a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 54a894907fafca040bdc8bab6e11cc525601467e38ebd334d4c93bb484971ee7
MD5 471a864b43c0d2195584916d62d80274
BLAKE2b-256 0a1d286d6d9379ac8f5743686bd70245dcb45169afc0866bc17934fbd9718fe0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.12.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f7b3cf7e18967b55a83c9365c134842e3715bb024186fdf7948a119a0e79ca42
MD5 71d2e079a4d57b44f0e0af58493c9fcd
BLAKE2b-256 796dc0426323d40b6beff830097a2c1a0a23683d2d2d4b4502ed6d8a87087a41

See more details on using hashes here.

Provenance

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