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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

plutoprint-0.4.1-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.1.tar.gz.

File metadata

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

File hashes

Hashes for plutoprint-0.4.1.tar.gz
Algorithm Hash digest
SHA256 e4f2c3b8c347f387e6d1525a932c49abe8dd1c417a8569e152c9132e9249c889
MD5 7abb15c1660b8ab4f09afc52f902182a
BLAKE2b-256 724e99bb856a7f0684301b988d079fb6ff2906c025c04d912ed8f10ba81d5166

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.1-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.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4a14f443331284831eee60b55ec836d9030ba4154955737f0dfdc639e9159899
MD5 2d0fda02be1ce1dd2f2d7709f6ff1841
BLAKE2b-256 74ee5de0320eef760262d098a0484ce888c022cd0f7cb88ce49801419a97f98e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2fd284d8d388bac4a2bc6b2fcd1596ed313ed481c4b3841b3bc532b3f7e128b5
MD5 b7a0190b70a0724cf2750f0f31bb198d
BLAKE2b-256 5b93c2756908d6fde4ba9bf199c84042bebbf2f859c5dd9be2ab4eb6b6544c77

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ad5090a2c996fae4d8e08e1f742c38a3de0a58eaa78686edb59b4bf238f54978
MD5 71437db01d0e6c52ce63107b92a6fcca
BLAKE2b-256 8aa52b4cf1cd69d904a29e4db4770d0bc471d4eb5a569463c515a2c2bbc968c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7c31fe5e500bf3791d7e10d79238ef54bd7f8c90156f741f15f9fdb162ed38c9
MD5 83117a8adf747301c02224640c74f9ad
BLAKE2b-256 0474a8afd5706b010a4e275c8bb06ac7a0cf0a64489ec16f46b83bcec4412b85

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2e0645fcf16c1b0210a5a783df40a952f2f97c1ec64c8741b4a95b5866b0253b
MD5 d86d427b82397bc5cd9627160b89fc86
BLAKE2b-256 e2a1d1e7d555d50799f147ead009f25178faf6b07d27c9ebeec31c9a1acf481b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 14444eafa8ed2061c7f8bc667e71f90be26b313a0f3e72fccaf060c92ce4e3be
MD5 8837c94c6c858e76eb06ef0177b2e287
BLAKE2b-256 cecdca3ddc8354d2ef83637a20afe1c395f16d3f4ab7ae1c28557559f46e1d1f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 498b38cedf884dc99cfa57bb7871a604fd00fdb791339cea14f47b4918d8586f
MD5 7dac6272f605d64ff380c0cb82ab9754
BLAKE2b-256 c661dee6eb632531134c8060b5cb589c63222a9989a2f859e0d45d7e2ad6fd66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f411c0b9813b08d0e34dd72d9eff8432840651e96e379f738e8ca6c840444f47
MD5 31a0af0460d14bcadf3089b9acee0906
BLAKE2b-256 1a75e7f202601d16b27e620291c7fb592b765258319b6c21bdfba6c81cb7d5d2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: plutoprint-0.4.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d5e3cbf71547e7238d60d77d6b7c16b4d49f8d7c29cb711e49142d7fc98f9bbd
MD5 d706f194842f2e05d976f13806f31113
BLAKE2b-256 f187476332d9cda897050563ee8debf6e5e332e60ef03381018b03516ca86d7d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for plutoprint-0.4.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9c32a0c1a548b464debfb19238d20af5ca50e7d9bdbb68ff94efd039c2498138
MD5 e3eb1d5cb15c9f66b7f1e069678dbdbb
BLAKE2b-256 8a58873791e1d6d66f804a2013c7be8b123de34b10f14ece99b9e0d72ba7bd74

See more details on using hashes here.

Provenance

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