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.

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 = """
<div class="email">Email: contact@example.com</div>
<div class="tel">Tel: +1234567890</div>
<div class="website">Website: https://example.com</div>
"""

USER_STYLE = """
@page { @top-left-corner { content: -pluto-qrcode("https://github.com/plutoprint"); margin: 16px; } }
body { font-family: Arial, sans-serif; background-color: #f7f7f7; padding: 2em; }
div { margin-bottom: 2em; padding: 1em; background-color: #fff; border: 2px solid #ccc; border-radius: 8px; font-size: 1.2em; }
.email::before, .tel::before, .website::before { display: inline-block; vertical-align: middle; margin-right: 16px; width: 120px; height: 120px; }
.email::before { content: -pluto-qrcode("contact@example.com", green); }
.tel::before { content: -pluto-qrcode("+1234567890", blue); }
.website::before { content: -pluto-qrcode("https://example.com", red); }
"""

book = plutoprint.Book(plutoprint.PAGE_SIZE_LETTER)

book.load_html(HTML_CONTENT, USER_STYLE)
book.write_to_png("qrcodes.png")
book.write_to_pdf("qrcodes.pdf")
Expected output:
QrCodes

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 = """
<div>
   <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'>
</div>
"""

USER_STYLE = """
div { display: flex; flex-wrap: wrap; justify-content: center; height: 98vh }
img { flex: 0 0 45%; height: 50%; background: #fff; border: 1px solid #ccc; }
body { background: #f7f7f7 }
"""

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

Uploaded CPython 3.14Windows x86-64

plutoprint-0.8.0-cp314-cp314-manylinux_2_28_x86_64.whl (20.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

plutoprint-0.8.0-cp314-cp314-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

plutoprint-0.8.0-cp313-cp313-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.13Windows x86-64

plutoprint-0.8.0-cp313-cp313-manylinux_2_28_x86_64.whl (20.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

plutoprint-0.8.0-cp313-cp313-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

plutoprint-0.8.0-cp312-cp312-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.12Windows x86-64

plutoprint-0.8.0-cp312-cp312-manylinux_2_28_x86_64.whl (20.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

plutoprint-0.8.0-cp312-cp312-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

plutoprint-0.8.0-cp311-cp311-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.11Windows x86-64

plutoprint-0.8.0-cp311-cp311-manylinux_2_28_x86_64.whl (20.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

plutoprint-0.8.0-cp311-cp311-macosx_14_0_arm64.whl (17.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

plutoprint-0.8.0-cp310-cp310-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.10Windows x86-64

plutoprint-0.8.0-cp310-cp310-manylinux_2_28_x86_64.whl (20.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

plutoprint-0.8.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.8.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.8.0.tar.gz
Algorithm Hash digest
SHA256 6b47ca216df270595afbb15f4bdbf9b0668bc782276e820691a865c724a80194
MD5 62990506a6cf2182c851f09c19a0f1d3
BLAKE2b-256 e0cb2a596df69b47fb582954b83f1b4dcaf52a878f7d86c577d207726e366d63

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.8.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 19.9 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for plutoprint-0.8.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c41cea121278c7404c25b369bd652fdf40de09957201b0bfaba55cdb109ef77e
MD5 13b1067a65ca623010d84d3adc4bec93
BLAKE2b-256 f507e4bec53c9b1aab00fb4736968e1b234536f3423b7062665c1c38b14fba91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4828fb1338ca7320ee5104324309c48ff3db36958fdb851be14342fb89b5cb10
MD5 ab9dd5779df559652a81f39d4cc0f9ee
BLAKE2b-256 69c00c3e7b35bc6fc4306c859282a3b85fd57a1109eb34498bab485e0832ffbe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 28c93dca2e9ac90c622e8af51211eaa39878127e0e210e206a038db78172fd54
MD5 8f0f6ea5c333f84549b1f3e13eba5e54
BLAKE2b-256 0713451c402817a24af7c378efcf3d9fc9f735dd4870fd83291ce16baf146729

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.8.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for plutoprint-0.8.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 783be9ca02f1f11515fbde9ffe5cbb59751af340b413e1903224f3524faa235d
MD5 22a6cd368f7f0082451e82cd532233db
BLAKE2b-256 a2f2ee0aa3dab9013a14c6bfa34615ae973de6283791acd3fa99dd37bd2ade20

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 af75fd40acd8d88eec0764d9aa859a8f0d6184f3cc4c724186a757bbfaee0cb0
MD5 4dd01b312584df2fbf2263a3bae4628d
BLAKE2b-256 dc16eb0612e89239dbfe8fbe4d884a983ff09b9e2d95cb39b936e6fd675def23

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a50d3da522acebc0899f5dc82a006b4a186f130ab49cdc383e6d0a2a07a37ec1
MD5 6a852c78f1717a63d9fc2820643445df
BLAKE2b-256 cd206b0ae2476f6de7ab1dc07860fcc1d8ce98140f1f5397bf9349e3b93000d6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.8.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for plutoprint-0.8.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5fb4aa66d26ad3aa9c3efa4bb5dfb9a5714adeac5c05d288e24078c19044aedb
MD5 bd9ec20674c93c4b87986dd560ceef93
BLAKE2b-256 ad96dfa00dbc58c35809cb05716dee6a426077cd0dba641ec37d917f139e2b29

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f0ab109dc45fc32d9c913f29ad773f0a6bc63fd69387c0d1c1c9eb009030912
MD5 c0ac0875ebbaf451978fcc2499b62d46
BLAKE2b-256 791b502db3774f19c563014a91a2e003fb305b56f2de10051fd4525723a52bc0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 01c2c4869074cade630f1e6e8ce129775f168bde995b02894dbf49742743a6b4
MD5 ce2321724e3d1497d5655a933b731fc2
BLAKE2b-256 db455c30c7a75dc52eaf2030ec845548f5983471f7312f9e2cf805c3d5657504

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.8.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for plutoprint-0.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9b42c198ee680e03f9d70a1a6203415770830b9d0e4769a3da105b077fdc9bfe
MD5 19812c4d7d712bc83635e6e506ed7b12
BLAKE2b-256 aede462e9a80477e597f8da35e0c5cdec45e49fd12cf3584169acf87f4cefdef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9ce094a6e2e03469266f844aa165227b0dd396d87b7aeefe4c33677213cbbeb0
MD5 5d0c7f7eb267a10a21c3d328d216487c
BLAKE2b-256 33bc369bd602adf39813fa0e00d3b11dfa76b6c188a88ee1e83776edbd9e1cd8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3411cca36fc51d38a0b8ef83bee8850e2e60faf30fd4ba1730a4552ff934c75b
MD5 0249c5166dee8de96d519906b1eb7671
BLAKE2b-256 bbd438f5cdbf8b93a772ddd48cfd940a9eddbe069d0b52c5c7e396a7ed101c83

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.8.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for plutoprint-0.8.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e9e693a18b9adab2ab9032c6e78f64d7793712d221b6357257ac06bd30c3bd58
MD5 40ec33058e23e1cdc601ed01b57a20c5
BLAKE2b-256 3f5624294ede4ba2586b888781eca043f862493a0408e66f0a496392bc43dcc2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 67fbd49e7a05c5c0db954bd49cc1f3663c90043f7dc5f37f98a60f349076332c
MD5 4801377f0645553a90faf2a0deee51e3
BLAKE2b-256 23e866f94af61dc68c8b71fe839953915e0e4b2a9af790102be4ccacc221562e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.8.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b515f796cfb92d5957d6c13460986a81f3ff8b44e4e25bfb911f643caeb7e649
MD5 ee946ce7548757100c0d18cff7bb164b
BLAKE2b-256 110823369827217fc35eb41d478c29492f20ca80250d90709f69089377e140cb

See more details on using hashes here.

Provenance

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