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 and Linux (x86_64), 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 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.7.0.tar.gz (35.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.7.0-cp314-cp314-win_amd64.whl (19.9 MB view details)

Uploaded CPython 3.14Windows x86-64

plutoprint-0.7.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.7.0-cp314-cp314-macosx_14_0_arm64.whl (17.4 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.7.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.7.0-cp313-cp313-macosx_14_0_arm64.whl (17.4 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.7.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.7.0-cp312-cp312-macosx_14_0_arm64.whl (17.4 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.7.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.7.0-cp311-cp311-macosx_14_0_arm64.whl (17.4 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.7.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.7.0-cp310-cp310-macosx_14_0_arm64.whl (17.4 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file plutoprint-0.7.0.tar.gz.

File metadata

  • Download URL: plutoprint-0.7.0.tar.gz
  • Upload date:
  • Size: 35.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.7.0.tar.gz
Algorithm Hash digest
SHA256 af09863568258188062b119bcb41917cc6a66bc95d1c6b1ec479eb319d6a698b
MD5 494c488b2725f72586e368c1e64e28a1
BLAKE2b-256 c68333aff545a0e96518e0c5f7315ab90ae14b55e672abf34630b79d14106048

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.7.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.7.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 213236e1b0d37a02de6fcdb6d2e7b6f25d73b6b14fc58e0739091d2d949d022f
MD5 01d03de9ef3cfac0c20cb11c93b5b420
BLAKE2b-256 60abe3ab562c497e395e05d9ace69637888b0592e26212737abc56b3fd7a8a32

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fec213061b2ba25333b986b87336403795e5147a4a10fe0bfdf0cb33c92c2dd3
MD5 b7545fa17e4f78276560236e5dee398a
BLAKE2b-256 f0a853a6fec11e8d3c170865cb18a0d3a2ce8fa3f58fd37357d81ab203aacce1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4062eb032ae1d80f291530b91d1d68fde3c686c44cc037b3c12acfa15ba3b5be
MD5 c07d896d5e4cfbdda0530ee476c2486d
BLAKE2b-256 ada9ccaeb247e9c2b7cd35637a84d6476831ccdd746ce043ec3dd1535d37fba0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.7.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 19.1 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.7.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e57b9da7a947728434b2be1f97b8e4a8c78e94be8d8ce9516f7453660fe3a736
MD5 b67b6b9e7d379cfd349ea80a0e44f42d
BLAKE2b-256 01104d5fefba5469426961cf7e71ca1b7fa4d1e66f2c8a6df337ffc9dbe564f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5462ed095cba3929f1b3d91a82050465811d0223d2930b8245cc96fd3470d08
MD5 1b0769539028dedecbd9120fcf650b57
BLAKE2b-256 351a7d3267993dfb9e1a702094692eb687d376cf604aefc0144b343a2b009afb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 06b643ac9f26bbeaa3aef59c19a22af0d07da64a8c49106b67eb195421c6715c
MD5 8b2f7a9ffe698c7bac86f89b203b8e33
BLAKE2b-256 47a732d0531cdd396a71be2e053b555c64d748d7e89de6c43c923892ec7a598d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.7.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 19.1 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.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 491f592892e06dc2c88985c55802f1524f45a81f4fc287dd51034161e63a3d72
MD5 b95a65035e1d57de42eced946e3df0ab
BLAKE2b-256 26922b20202710d4ff24083b645892db10a605ae363e7d589c320155adcb1499

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d4bb0688868230db3ce63cde7ede92cc4079bf29ef8b3f7a9328e1bda7353975
MD5 88bc91d6744953e95bdd306bfe406750
BLAKE2b-256 851c33003ccf36dd834d06085d9690f93538fecab9387f068300e7ee8deaaa91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b69751a9d2a69eb8744b39258a5ca48e02b14f56ba71c92f76d374f80106ce1e
MD5 d501c22741b4d0b9e05b9bbdaca46294
BLAKE2b-256 f681a32a573d8b93fdf4fa7cd3597a35d93480cf52cd71848655b18a1a6563cb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.7.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 19.1 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.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 121580369c67a47e6f62ce52f96e82d6487e3b83a0457f845d75df1571c4b56e
MD5 a4e0d71d3838ec0b5bd7844dd2e21dc9
BLAKE2b-256 152ae614fd6f9dea0c875048b236170833c39e0f10b8b82917a9287dd632eae1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f1eac21f5ddc79d9ee3a6a66bde8cdc5958b4a9a5d39905a2bad25235959556
MD5 56ab0c797b2ae55499b6276720f3543f
BLAKE2b-256 caf4a3b0b73b37b7f6f9a97f03614a263490da7a509d0e46ac37dd8873e6e96f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 83fb6ccf967a7b0027792686daf5bd6e8248c1bf449ff354be887d78e93154f2
MD5 6ed17c0f234b2af7dddb3dafcf524f38
BLAKE2b-256 ac03d460553bbbdc075e9f2d794ea6c95ff742198bbd71dfd524f261528dac87

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.7.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 19.1 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.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6086193842c217a7d00ea44742b016cd9ee4f945675ed63337fe8692c0aceeb9
MD5 977aa800d5fee4ba4b091b9e82d1b9c4
BLAKE2b-256 9396be85a9e3c0ff99ede0795488ce802e2fa9770e8b1be0c1b674b7d337f8d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b910298fc3360c7ed8c05e5d7d9abdeec091896228b45f7bf60ec94103bf114b
MD5 01fd24a32fd376e1bf7eadac1f58694c
BLAKE2b-256 b2efde9dc21b44eb30ca487c593237322639549528c50686033c82ca6f379cf8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.7.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d5d06eee9191936c114b3249aa813a3bd4b93a62a1556ce168328c32e4de65f4
MD5 537a784e2925174d9c2262fbc53d6fa6
BLAKE2b-256 478e8a9cef022f127366964c5133d61a8831b5b9976ff1d34abf0a8b6e16827c

See more details on using hashes here.

Provenance

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