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 Distribution

plutoprint-0.5.0.tar.gz (34.0 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.5.0-cp314-cp314-win_amd64.whl (19.9 MB view details)

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.5.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.5.0.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.5.0.tar.gz
Algorithm Hash digest
SHA256 cb35a9fb4088f356e1ae82a0e3c84d1fb420c1a3d314f61c1086eed37ef9d63d
MD5 64454dbc84abb0eb2640ffa6d0188a6b
BLAKE2b-256 2a623cc668263c427e91353ede5de966681bc9cca695a7031542e03f8d4b41a4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.5.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.5.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4e5a6ad1a452911e5d6ffed1e9139b065df6f3edc3b74327242f32885f32adf4
MD5 4b14d910adaa3b18e595f10110ea3225
BLAKE2b-256 350299574ae74ed611a14e5b5b839a07c88ae53ff99431032e747c31d4d51b6b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 44e5e4ca7017f3a65fe2213d29ac01a4f6513b324d5ecf8680faf8eb6724aa2a
MD5 2cc4ed960f3b6444143909255f376af4
BLAKE2b-256 cc778689496cbad429efb4e56dd8af05aeedda8a5f212147291d8306d4f6c346

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.5.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.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a9d219dd6c933607122094160ad683296eeece011a5ca2b09fd966ae1941205e
MD5 3909073e7edf82c99a67bdad7657753e
BLAKE2b-256 093303bac4e4631f4a150997dcc4d81354b9733fd188e3da7862c3d795cbdfcd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf78d7353372f3b53433e00833dd7eae02e63673de3faae45835309c5f738895
MD5 becd3e188d10542866b3ad2c3246e7d7
BLAKE2b-256 71ec55bd094f516ff988a384f55e0dc3d9895556fb4e25a48b111a8851033ef6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.5.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.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 29c9c769452f319f37df1429df4b174e4aab61215ed160648b1973267ff7bfd0
MD5 9b9108833a115dd47ab7d6fb90682688
BLAKE2b-256 cba034f215e34ecd4fe0a692719e48d1222c65032cefad744163182e3a965c45

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5ce221cee5812c88d76f638def14e74575a83b11510e27fee6fa486a7988be91
MD5 7f61d7b7ee90cdf1086ccd2550d204eb
BLAKE2b-256 965bd7c3ab47446e2d50ee375f26bb0f9105cc5922a9395b39e55de31d1c14e9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.5.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.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 21887ed1b9901ebcc07075a6a3b3007dfe55dc94d0d9e9f1b1ef2b017f652088
MD5 83abdaa2bff5f2768d97ae62b5281d79
BLAKE2b-256 43b50c46a0b1906f4786b761dd7e46a0da763500310ab55c5ac2cba5ce6108a8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d11318a037e6d5bdc250fdcb8254e5b0ba60c3eef62734d709054462b8db620e
MD5 2c929d658e09e809cb0a7672c6aeb97c
BLAKE2b-256 27bf980ccb75ff9e08bf0b9b6ed49967c4900a7b94e0947d889124ef3861c4a7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.5.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.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4e102e508ad35f2dd168b90ab0a41804e7a00321fa0e2dcc14a92cbdd12b384e
MD5 913882b0557eace614fe2f9cba5acec2
BLAKE2b-256 ce2eeb39ab831196946d0cfc422e4cdc766ba1531ba3e47b72abbe40dd296ed6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4c92e8a14084eeb64d97b1b8661409c81f743f167341548a8da54f5d4baad50b
MD5 b40bbc5b262de719e8109e8bdfa1153e
BLAKE2b-256 f1c5c495109314bc2364c9dcc90f578aa4d64c4893f4f972b4e4d70c27ffa6b8

See more details on using hashes here.

Provenance

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