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 depends on PlutoBook. For faster installation, it is highly recommended to install PlutoBook and its dependencies manually beforehand. Otherwise, Meson will build them from source during installation, which can take significantly longer.

For Windows and Linux 64-bit users, PlutoPrint provides prebuilt binaries, so no additional setup is required.

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

Uploaded CPython 3.14Windows x86-64

plutoprint-0.6.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.6.0-cp313-cp313-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.13Windows x86-64

plutoprint-0.6.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.6.0-cp312-cp312-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.12Windows x86-64

plutoprint-0.6.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.6.0-cp311-cp311-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.11Windows x86-64

plutoprint-0.6.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.6.0-cp310-cp310-win_amd64.whl (19.1 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

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

File metadata

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

File hashes

Hashes for plutoprint-0.6.0.tar.gz
Algorithm Hash digest
SHA256 925333b8edade3d867d99d8a484a835264edb659f78e73526fecb0503482d288
MD5 aaa3d545e4c200c75f297f0b16a0c28e
BLAKE2b-256 008be13bb40d0566a92ee2ae74ef7beb852ecf6300513600d62f991d1a2b4450

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.6.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.6.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2f2bd32c6bcce796a0165ebb1215b2eaa9c5f8d068924a357e2eeeea77ed3c34
MD5 0ed5e09ebbf501734db99534d76a0f64
BLAKE2b-256 285c17285373de0152df3a9988c766cfcf0c399f23e75a16cb054431f1d54607

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.6.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 44900da5ffe9e54b1af8617ba69a6c361fea8f8e45499dcf141643696356e174
MD5 3355fd1bccc90235a6ed7de0c985aa78
BLAKE2b-256 48732130fba351df60d7ee323d8db751c4873619bdee7f87dc066f87216c82cb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.6.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.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 384942f51392d9cbb0f2c82a44f98302e9b05e3b7a31699300e1a7002b33554c
MD5 5b91a2e61d3d07a5154941806b75a6b0
BLAKE2b-256 91d0075a9c3aaa44568241118a074c59010cf94f283139822d4bebcdb5e81125

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.6.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 58319a6b984f55eafb72ac3702a0d94d3ee5c2186f1597106c3f60b5a85f8109
MD5 9b64bd0fe0330b92ed226ae5c7a241cc
BLAKE2b-256 290c2ab6fc64753b04f13ff058cf2324f6853d7269ba960a53a813bda790f244

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.6.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.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fd835d00329ba65348e28b9394e618bc8651a0b28f9fe69936936cbaf040a645
MD5 5d5357b841f299ea1774a1134c4846fb
BLAKE2b-256 f3efc921ab7603907889d3ad809bd316899e0c15ab0e7538cb5b436eebd8b759

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.6.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 717cefb27ad211b91344370a242fc25aec937cf50dfc13238cb3e7c8f6136f57
MD5 ae4a017a5d8c06b2f9474fb73b5e7ee0
BLAKE2b-256 e32a8143b4fb4541a0897d1e5351e0097e347b1f476a4a562d81e5c3606889cf

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.6.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.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 99d03f084ecbf176b52e53bd4601c472221d82be7f26b320d04e135a731e58ba
MD5 87c53d1ada7f035727466bec5fe31fa7
BLAKE2b-256 b00c9fe636694522777de603c387cfeadd74b3c92e30d55f9714c352db78d865

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.6.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6697a968b7a961b6ccc2e61db226764f52dcd28d54a65228fdc4c27efeb45d61
MD5 9bbcdd65478e195025a96910c23a2e5a
BLAKE2b-256 6dfd9124b10ca5742989d5f4b4de0d24e42607072de95a12c221cbc7b45da574

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.6.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.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fe44b216e1035fee7fe2a17fc3fd30d393991e006e62925dcf2908522f5c9fd0
MD5 6abf5d4d2071441afbd09cf92b751a5b
BLAKE2b-256 0883eda5e0b0f3beb994da7186a63369b0f10ee7de959352d7d8bebded625042

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.6.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4e1f3d7d5e3579eb9e02d29e4ca83388f26d973340dfa6f94cf578722dfb23eb
MD5 3aa2f306d936b60670b99b3cc85876dd
BLAKE2b-256 40588bc993d4df02e596024c0bd851c2ea39a0b79fdb59304c6fead27084ffa6

See more details on using hashes here.

Provenance

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

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