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("input.html")
book.write_to_pdf("output.pdf")

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 }")

width = math.ceil(book.get_document_width())
height = math.ceil(book.get_document_height())

with plutoprint.ImageCanvas(width, height) as canvas:
   canvas.clear_surface(1, 1, 1)
   book.render_document(canvas)
   canvas.write_to_png("hello.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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

plutoprint-0.4.0-cp314-cp314-win_amd64.whl (19.9 MB view details)

Uploaded CPython 3.14Windows x86-64

plutoprint-0.4.0-cp314-cp314-manylinux_2_28_x86_64.whl (20.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.13Windows x86-64

plutoprint-0.4.0-cp313-cp313-manylinux_2_28_x86_64.whl (20.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12Windows x86-64

plutoprint-0.4.0-cp312-cp312-manylinux_2_28_x86_64.whl (20.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11Windows x86-64

plutoprint-0.4.0-cp311-cp311-manylinux_2_28_x86_64.whl (20.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.4.0-cp310-cp310-manylinux_2_28_x86_64.whl (20.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file plutoprint-0.4.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: plutoprint-0.4.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.4.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 358929982ee20dbf98579b4a5df0e6e6f471c0a3adf6c123d6603078f831c13b
MD5 f3593075f66206c9134b2c2e8cad269c
BLAKE2b-256 8b31c2d0a8f53ebf95a7abe349cdd2269531b8cebfc296d32be4b51ffc804e50

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d2add29d13628d0f11f6b9eef9f1a0fa65b8d8630388b905b87619bdb9f4e032
MD5 8babf56a137a5279e40f42b7ba0bd39d
BLAKE2b-256 bd633d381d8ceb003107011417968b12c6aada1e72112a94c2ce9d043603e0e5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.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.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5539ee06b3d42531f7d5bf6b1f7d3c3019e30f8663524196e0a6995af0ac77db
MD5 230829327c61a4d57c53c224a4fcc890
BLAKE2b-256 ed205a7c3fc6cef93ba685a972c161b43458f4b7542bef6c6af3684d72c7175e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6cab63f5f2652890e1663a060ac3a7cbdab4788903d4a5fd6044314ae52e84dc
MD5 c54db814340f5ff198bbb8969a2686df
BLAKE2b-256 0e04d7f7d3c5832f9539062f26ceb221429d2fed7e1e268d48a0abeae1172028

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.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.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 65bbb8fba0156cb34337bb2ca40087127b281a71da692b984996e9e589191394
MD5 5e49db82a2efb0bc42b533426ad713c3
BLAKE2b-256 7e5205c1f6037dd1fdb72b0dc25ebffa7ef55028ad9371e3d54aca0c7206feb7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 970a287c3478c8ce695b26dfb5f545ee06870f933202a69ef1e3d656d81965e0
MD5 2230d77f36c797aaddd948beb70bc5b1
BLAKE2b-256 37b9dafd68e77a056ed5acf31653492e106389f43304fc737d70d704c08a78e6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.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.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c9f76cedbbe6e506159d1b88cbe68f98f4189ea78e3d70f73880b52d4ddc7177
MD5 155471e74b2572db1cb724a4c7c20592
BLAKE2b-256 8634fe0d7acc079c55685cb423ca14d89672f947e4074ef0c5e80403515142b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a58f9e2919cff8acd76529c34fe3fa5e835cec8ffc66433a2266fb0a0d35010
MD5 0a8dd2d382982680f53d85e5a9914a28
BLAKE2b-256 9aa0b63022fca0d596ce052966a8517d382d267fb7876c9db1accf6cc32805c9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.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.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5df64c14f0520d92c509b2bde9eeaa0713a1b60fca7f512674550eef62ac6b78
MD5 9ff9e7e8887770130368aed6a4b39d29
BLAKE2b-256 dfcd79651b523a394561ea66592316cc3d8ef4dfcb1d6dee0983a04be932e50e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e24330c62adc6f0df5f818c4b890ee52c95e742d674248f04135bd44f3623ed
MD5 0e833b97283b0ebd1b9c3c3a7d4ab8fe
BLAKE2b-256 6341f0c62bc1f25148e57b47863443f2a600430054a9c263fa3cf4c30d38be28

See more details on using hashes here.

Provenance

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