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

Uploaded CPython 3.14Windows x86-64

plutoprint-0.13.1-cp314-cp314-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.13.1-cp313-cp313-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.13.1-cp312-cp312-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.13.1-cp311-cp311-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.13.1-cp310-cp310-manylinux_2_28_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

plutoprint-0.13.1-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.13.1.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.13.1.tar.gz
Algorithm Hash digest
SHA256 5834e527fae129ad7913410e20910eadb491c1f1b733447734c0dc7731a19ee8
MD5 1e55261e477c92f8d3cbc7da95f0a206
BLAKE2b-256 ed6a3ff582860b5d1f99b541ca3dac30a5bf2e146b79f8d0b1744bc0dc69b84f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2266af21b07e28284b3efc6ad5a313b766c9d0b11ea78f9338ffcb27547b7b54
MD5 f5ebeb51f15473f615fd7e3422e18a4b
BLAKE2b-256 0fda404aee89cb183a5b0715014147e03aa8a98bd00d1564d92a05157be2d02e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9667a6cd5237c3a30db87ad365babb0e20da4a1db9e1729a95887b48a5225f28
MD5 7ba1a7577ad7c3d24d0ac04edabcd888
BLAKE2b-256 a5fd0202221a48dd696463a684378077620368e8d4259bb47a4181b755ee884f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8849276f22b6535bb44d3a514f7308081d4b36cb882cc6f332bac2f3b7f94a38
MD5 89f81a8d5fc2fe81c3fe91b66199792a
BLAKE2b-256 d745651751e8c95df473c74d0fca07426fef6a8ff13c2e9430180bde09be5622

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 400b55514f40e23605bda6ff69f354ff26ef99dde8a3c9ce6a8478157b109d72
MD5 2090ca5461eed6f42a7203b3e1b6436f
BLAKE2b-256 7c19033c13f5409aa108352ad132746a3e3f34e71d4799ec59f1d0eb3c35bd51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ef41c63a734c393715349d6d0523976c2723b414f89ee1bbd249d51391ac966
MD5 52454a7b4ac0790ee3e8c49e881aec41
BLAKE2b-256 13c723d17ed0a4385ff3141c70012b6187c53398ebdebd277cd47171dcdd00ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dbee326e7bf1f56f99f9803d605951674d0d707bfd92883a244de3b66b4bc0fa
MD5 1bd6e8f4f412f2eec1a5eaa476e86e21
BLAKE2b-256 6fe2a09fe4c11a05714465fc11ddaf12f4b8c0de49a7ddfcf12571324936eeee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7ffdd0177fd52d6cc2f1687f8788573c42bf10be2df15b9b2983916fa3cb75f6
MD5 a8fa25645253ac63a88f9851a90668a6
BLAKE2b-256 40380e9860de929052ab1b5766f83e026321a7f4e369d932fab6ccb2b8e02ce0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1a51e1ba8311b2ddf6fb4de6810b21d18f5d15a3d43611936bf44d8cca6be2d5
MD5 7683611393b7a30dc8bdc02b5a2c1635
BLAKE2b-256 65e055893842b040c563fc43c9ce50247460862db5f581c9f0032035bc5cb421

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7b0cfbf30b8041c248128274fd741976e7524b6b9132d0756bc6778258f4b81b
MD5 a110626003f326667fe11a3300d29315
BLAKE2b-256 e1c74a8c77dbcda19fdb49e293eacc85497134f2527625034a2497de63dd26d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 601e458ff5d47a5cacc9d816cf94996ad59c14de924a40656cea2201da4d3182
MD5 98bb31919ea211bc80b1fe9f92a751a8
BLAKE2b-256 6eb642df5c16b444e01acd7a54a41e86608379d4a533eb77b8039fa712efb129

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e3066e0daf092f1949ec9619b4921ce8cb04261229cd4b70b5777fef0ca122cb
MD5 1bf53eaaa44d3358500c0d13f53a50fb
BLAKE2b-256 c25ed569abd054c103ad4b515692a1e1c58c5c55fd1b5a761419e14f8b37a0ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7c90bf9fd52e43ff5214f480b7497155a636892153672443346958e7ca8e786d
MD5 dcd1db94c7f459c65de3187a15456e7f
BLAKE2b-256 c0c7c53afcfa0949ccc42067d95d53f5d2ab763242d0beaafe9287e83be8e5fd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 295986b1e87fa44c19a4f1ce593fc3ab46a1caab772716c5aee64404ff4a2747
MD5 1dacc8c53719e5fdcebb35a15827d6f1
BLAKE2b-256 3f4311b67c4f3162358faea6bedcc683ac18d018dc3b9612c33bdf048c02995f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d6f7e46cbea5bd902cbb4150f3999c7e61618a8162b73a5cf10bb62284b401d6
MD5 cdf595bed4233528d687fd197f32b7bc
BLAKE2b-256 48a16633cfa003d8d8268b67749eff0a7dda1d85b3c5b0d01adab6760f0f018d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.13.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3432460b3413d7e8ed0ad2bac5ba8ad8f2ef3ae1917268e995f3541eb3dd1c2f
MD5 0b79d51ce6ffc56089d218c6402558db
BLAKE2b-256 e3303f5466d39a876d0fe89e5333e536e1d87f678cf5bda895687505beddf890

See more details on using hashes here.

Provenance

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