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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.17.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.17.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.17.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.17.0.tar.gz
Algorithm Hash digest
SHA256 361bb13f152c31d03023f91a0bc81706cda0637f795c43f5859725c1d94c9bb5
MD5 4104acb897a625467fed9ae795f852b3
BLAKE2b-256 9ba378151c5bc81abe3586ee09ef5ddd6ed193220641bfed10f1b07e467f8852

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3425386c81d88d35fe1ac88f64e83bd35195ddc6082fb4819d912d85bbbab507
MD5 76be9d2a238e9d1e0ee3d18c2e16ada6
BLAKE2b-256 99f6e8a4c2eba8bb30416e4f878e6fb1fa8258a88c84d85c70b31c9915943568

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d091ec8bdc4bcf5ad59cce55b9d12a1514a9afbc1e4c445349c168b200881045
MD5 be0c2b96452285623fa390bb63c06ed7
BLAKE2b-256 135c0c73fa1e4a558345f02b62fb7d72b24f935970aab63cc2daf7d4bf56734f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a1644386ab9eaf53a215966186c8094bb9a5d1bc1abbac1e83164c8754bb253a
MD5 c7faada1be7b332ac22dc8693d6b3c41
BLAKE2b-256 d7062439bb8a888532035caeaab1e2e686bcec8ed81dc0928afc0be10cea1cba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5854e1d0926d24272de47401c3b128eeecb17043ce245c62d9cd798ecee8a5c9
MD5 b0b839d9cdc6ff65296e193f013a8d6e
BLAKE2b-256 bd81cad88182582888a7bfd6386579187e1fd3e0422a0fd493d8da97f01a9dcd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d7862ef600233797c2b619d9e41cd96220a637fc17b9e9ab442a151faeaddbb
MD5 e1547d6ec8b0568a001863108a8cb200
BLAKE2b-256 0f4a95321f8a01748f75e8f5c1ec784c92a8ac4f3abb3896abb5ba0c768264a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d16aa088cd9ab21259af9bf9451089e21db80373e52d1468e2d7fe0c3b758b6a
MD5 88399580728bff5f8921e55fcd88bfbd
BLAKE2b-256 09eaba5eaf3734da6f910d99f27bbdd2fc4a61a2139b257a61cdc97ffbf1e712

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b1c9938b3f42782ecfeb28ed826ff97738e42e8e99dab819e8f62c0f50472e93
MD5 8a70182a2ac818857f841416c6305975
BLAKE2b-256 ef5fc1f4e0d7156849518060a634be944018569e9d33e10f05da4f7102513846

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 49e2e6c2b64da179f2a2c52fbf5a6383625c1bddf59b8019a3a8184161842708
MD5 49bb334a96f9d480a3938f36640c3a19
BLAKE2b-256 81a2d6ffdcd0e7796b5ae70ea2880167e51eb4e1513254347f84643e5b4de4b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ed5afd50b64a1e1c006ff6a579cf5e34962b3ecc570f2284c2c3a92a54184c63
MD5 20940ba3ee22e990024a65aaa2f22877
BLAKE2b-256 ba24e9652cb0ed7de8c18a6db209f3b3a97faf60de57b4a1efabdad61a5d06d4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 47114585e0c3611a60281574a7828a364d633ce85d8fcdbde6fd887fcdec963a
MD5 8f2e0194e7c0a502903f6fcfb1fc7283
BLAKE2b-256 bea34f89b9b8928f7f733ed42d4802bcafd033854a04dee28ba27be8189f388d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a8536a8d7ef538ac748daff1960a13bc3dfa7bc136a624d4dc62c30302b40ab
MD5 7db5233c5a9a079039089eeafe402f85
BLAKE2b-256 bfae6a3b3b157a7c2fa8c439433044e6989628ba3acf65a35b6e82aba3184e0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d06383d2c3644fe3c2ab02b04f7bd6a1e722ea48336919de5016360284e7a261
MD5 7bcb44c007ee22ca210f5b8e361f6650
BLAKE2b-256 07f0e4227e28106040d95b436c7b449b4d6a859071375f6c5bf8689cef9672d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9ba775a3ef0ac393a33d40333776a4d107f32d80a431d4ffede083cf82331ee5
MD5 5dab2408c540e97054c10098ef5e8127
BLAKE2b-256 4d0fd3f8dda16827203e5f03eba4230160814a0001cd9e6aecef721078f6c910

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf628b31c9d594dd69539fedd40447c97796bcba1a40fa716e7898bb551a0377
MD5 c438365b59ebd89f84ec8a8b2c64af45
BLAKE2b-256 7d8d69dea87ef8ace637f134dde67b6eaec055897e5b0c329195a880ebc3d500

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.17.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4cc2e76dfa671fa917dd55b17655547019946e44cc6819cb7c951fc5bbafa339
MD5 aac6cc67607f89207145e26dcc61554a
BLAKE2b-256 828cef350c4d9908e7bc74821ce22254c61c02cef468ddae0fccbcad255c895e

See more details on using hashes here.

Provenance

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