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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.14.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.14.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.14.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.14.0.tar.gz
Algorithm Hash digest
SHA256 8116c2fc739329ece9aea1eb8e835c77792e3a7f410361838dbb7252491cdd29
MD5 34a5fdf606b6f59897dc52aba705be31
BLAKE2b-256 d9678adc356edbeb6efac8cf16f90121fefd9eb65ec3478c5268be284438b94e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 21e5e4012bc4aacaa7c6632e2cb9b43b6479d54e12cc1c7b53788bdca3d85ff8
MD5 4ed4620ebeb0662196c3ec608f5d515a
BLAKE2b-256 4e8b2c2426f9bcd5cdb2c72d6a5b311d89ae152b2dc4ce73f8783c0c3e58b72e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47948a3ca527ca42d6baacfd78b5e18d193fe21a1559750216ed996c8da6edb6
MD5 16e7873f6842935efce4225cec3127f9
BLAKE2b-256 45ad8929c74a304eb1ebca72a3370dfb6eb90081e15784acc3c5d7b06fdfe528

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fb69ccaf093d2fc2063876e9a3e85b6647e3a64d66fadd0ef09239945608786e
MD5 d87c77de36034fc0a025d13b4dc82496
BLAKE2b-256 5d1789f7268bde0acbc289fba3e36b71192489296767bcb54cb877d9d9bf0546

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7e544d9e82531132d3ef1e3b41a18d78a95d1637b73f2220b50f2b0ab0772c73
MD5 4e03b2f9ac8a685cf517fe5b9af5e5e9
BLAKE2b-256 e7a92d0a2c39e693d6df9b71ee695779c05f7d320efb489ed20805a95aa4b146

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 93a9a5cdc33331d110bfc267f0e9014ede2cdd66ffaeffccb0331a64a99c38e1
MD5 a85e7bcf6f7eb2b07ffd7e1d27f43d97
BLAKE2b-256 897bc413fa459de8b9ebdfd257b81f05962870d62a94ae0cd95354ddc56fb466

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a53a7aae0862d935d4c0834c189ba7d82e67d878ea5f3594b80d3807d7a337a6
MD5 ad2217dbe1768f896a1d6a24d1d8c0f2
BLAKE2b-256 a64f399ebfd90e023886ddcb329f765874f29dcb8eb21856036d22023d75916c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ac3559773bb96b0746a625565b3d25108a4bb3b9dd56b6f45917e3899dd7da66
MD5 5ad8490e125d85112d75cdfddacfccdb
BLAKE2b-256 eaf74f5dd6c72f1ee4e96ed4db54acd03695e16e93c69a105f021cb12828a0db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b37cefae53d78d3438e208612b801c8b70a7f60f9c4c88e1ed302f0fc624e150
MD5 57ca20446bc25332b1df2613110cbceb
BLAKE2b-256 2a7999558e1826b28ea431edb3e95b9ed6da668c983db3d348c8a78adf5bae3a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5e6a15023afc1b1cfeed1ddf63d5b0a08e92a2d94710858991e6e85c11cfec67
MD5 bd548e51d2e39e63cd38c898e84f0215
BLAKE2b-256 41671069caaaa5cca072b00613ca7e78d74c5a9a050b8bdae58c5cb9a1961b71

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5d221d9cf972e01dd8235fa96133ab8ae38b18c828c54b8515f47706ecef2822
MD5 db2448a23d1d2ff51b766fddc385a9d4
BLAKE2b-256 bc876dce0ca434dd7c2390eb0ca7db21107d47aa5724377bdb66518d0f72f8d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a75084b87363f3580d5b943c982bfe8e6a9d03b8bd72032d657bec53338f7638
MD5 e2b5e3ae2d5e766e6a1230ec9ac8d329
BLAKE2b-256 38602ad162664c9f4dac21dd90034e9953daab8fdcf41f0d03eb3999bf8e5203

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4b8b223eff9198afda603c6374bcee28ca79913f5fed4c9502b48511f0bd27d7
MD5 1845ca69044c31f6059c78ad36510922
BLAKE2b-256 c3586b69e74a5255b7c1d232753629caefb7de3a0ddeb3d8fbc7c1ef7297d4da

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a16e9554c7da4cb7f0407d1fac7344f889818f06007e40f22431830f4028a260
MD5 f08c80f5951c7cc22b0ce5acc911a6f4
BLAKE2b-256 228eac6c800f82a98dd98b9b92f5702e31c185804670cf0ff98f7a242917a315

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4ae632140356c676d61c80dcc883d526b076b4f26055d12473d0a0a84206b731
MD5 28fc74f6cecc07e7d2b6ed5080f388de
BLAKE2b-256 d73773788b65cdc3676ce7d5ba7e2f0c9393f7b6cd68a61ece61e4af92103066

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.14.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4bda904eb9048e030f09d9d116866d17538efeb56d5972ff240cda237f99dd48
MD5 f6b611c94ef64b64238d396f30106eda
BLAKE2b-256 b860d1786d31ecff87bd92aa14fdeba016f8f05e1cbbe3b70faaf2179eb08a4a

See more details on using hashes here.

Provenance

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