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

Uploaded CPython 3.14Windows x86-64

plutoprint-0.18.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.18.0-cp314-cp314-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.18.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.18.0-cp313-cp313-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.18.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.18.0-cp312-cp312-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.18.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.18.0-cp311-cp311-macosx_14_0_arm64.whl (17.9 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.18.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.18.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.18.0.tar.gz.

File metadata

  • Download URL: plutoprint-0.18.0.tar.gz
  • Upload date:
  • Size: 40.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.18.0.tar.gz
Algorithm Hash digest
SHA256 53a633a070c3ffbf8811078da2fb0d69102f4c4abf3a28e627e15ffe74f31b0d
MD5 82f52eca25def1a17b03278016dba0f5
BLAKE2b-256 67cfc86981109f4f56682dbd7372a6a033e4eec2b92f8f29cfdbfe900062ba18

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 877da7fa982b09f036a788841ce548022203dc9bb8e0ca035f669ac4fb0f6456
MD5 2e61d3df450765623c6f31aadeb0fb7e
BLAKE2b-256 710c1b33e1c5a6b8169a87d99c9348c4763dc4007c723fb4bfd26b1870237ac6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a91e03487b65c880e1bc7645772eea26c2afcb008702c80511f36a7bdb29e898
MD5 38b6ec9ecf441a5cdf79fdf7aabc420f
BLAKE2b-256 41495228bae14fe3424c392871d27decbf90639bb13f71d82583881886f6e93e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 48ced1aabc1e73ca3d1abc40bbfed1190f0b46188d1b9f0d3514eda9ca05b424
MD5 76d6bc3f8e06626e253767b087fd07be
BLAKE2b-256 177dd0c60afa54425e1b630ba46c04ee5a62da791efa3537e9b740346e549b52

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 eac77480b0a41b4d22d9f579a2f5a99132069042da41d0a0d82c27dd97ebab8f
MD5 7fd0890ac43c6f2118ee9b936cca021b
BLAKE2b-256 e5c54cf404b17694419282735e1bd2d9ea1a79c6f7af28dc5fa1feb80de897a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8f86cd05a5fd91955378c6aac99e5bb2b5b5eaf5132cb4cd03ab350ac4812274
MD5 6aa40281ee0faae6b551fc538a517572
BLAKE2b-256 1366df9bf43a5f25a5c8cd497721aecb1666f7c954e01ef7f4b6e7830c231c6b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b077e0ff8b91c9b7e8accb6b1f90540e3344b009a45a4084fdcdad9e29758ee5
MD5 7f4b79c9a544214d466230f0edbcf475
BLAKE2b-256 45f1ae3376cc56f57cadc2b956b40f4756a3399ed9da2f94cde74c5d9bd38fb8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a37883b7e610da6a1b4b2d95a5e5a98676f547a585f196fd7d5249997fd244de
MD5 8f35701f71b646c7f6f98a8931937e67
BLAKE2b-256 6365d510cb98ec7733afc02d8df5d470de4a58b25fe727567224fd4e5c40b80a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 355f473c80a5e774dfd1890620b46cac826290dc9af884e82d0040730b54327f
MD5 2431f1805738ccaa80367576dc44517b
BLAKE2b-256 82f2d9808498ce5f182177360cc080d1f15352bcb9f47864dfe2d7b6e9792734

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e1600288bc9914fe75d8400b993679b07bd7d1d1199e04909b3ebeeac2861509
MD5 763be5c15c06d9223bdf0560e449bc00
BLAKE2b-256 5fe8785f2e2c9bc552fce7261636267924d8deeecf5f3796e09723e660d15ab4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1af22cccf798b43886ce0ad76101a9426b128f497d8f580048d2166b928789a3
MD5 819cc4064cd572d6969d816627f4280c
BLAKE2b-256 f6a6f0a38f6be67c2e43f3d0c6b0d8c0bc76a7f76d69f0eb749c526296341fc0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef769bc770cb594ca2d647a1e421026974a5a94f2a94cdf3b9b2e706005646e1
MD5 b139b4e48195aa405999309ecbdc7c62
BLAKE2b-256 54af7b747b1a61767d11f0beed9805465f5bf06e2a27b7f69dd92fa14e9f0d15

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4fda46b724a862c705cc625733716b9061ed65a07e131a69f60c1f4c540e44de
MD5 30126adfd6e50945f87c7be65fb46747
BLAKE2b-256 7645f573d41d2b8ed6c8cca3c3889e79d07dcf91aec03dcda141f92859aedf41

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ca44ae17eb979574c0bc689a0c94093739446b393383deef9b7c77a4d7dbfa3e
MD5 05d07566212453cf6c74c697f8f15ec2
BLAKE2b-256 7de95a7d3b5097600508790062b10aaafbb416ec6a228ba67148d77baf050e80

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c9471958248d81a15c97266d243d6a285b26b4533d27c792ae448eee696f7724
MD5 a388cf0f0c47fbc9b3dfec6dcac2c38d
BLAKE2b-256 59e4de0346e5934ad3ac35a6785fd78c479b336feb81d27a2595644433fa280e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.18.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0ebf5936cb979168dfc42915be00d484199a1fdcbc42a255a610152f2bc02d3b
MD5 a1196909a2c51729c4ad07127f711509
BLAKE2b-256 992ab106ca7efaa57fb1767465b07a00e228a9d880231e225f5ad0f4c47b2a41

See more details on using hashes here.

Provenance

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