Skip to main content

A library for converting HTML files into PDF. The tool uses Chrome to render the HTML and print it into a pdf file.

Project description

Pdfy

DOI

Pdfy is a Python library for converting HTML (and anything Chrome can render) into PDF. It uses Chrome printing functionality, so the PDFs will be rendered exactly as printed in the browser.

Need for NLP solutions for your business?

Rootroo logo

My company, Rootroo offers consulting related to multilingual NLP tasks. We have a strong academic background in the state-of-the-art AI solutions for every NLP need. Just contact us, we won't bite.

Installation

To install the library, you need to run.

pip install pdfy

Additionally, you will need to install Chrome Driver.

Usage

Using the library is as easy as:

from pdfy import Pdfy
p = Pdfy()
p.html_to_pdf("html_file.htm", pdf_path="pdf_file.pdf")

More control over the PDF layout

If you need to have more control over the layout, you can pass additional parameters to html_to_pdf

options = {"paperWidth": 8.3, "paperHeight":11.7}
p.html_to_pdf("html_file.htm", pdf_path="pdf_file.pdf" options=options)

The full list of parameters is available on Chrome's Developer site.

Not saving the PDF

In the absence of the pdf_path argument, the html_to_pdf function will return the PDF as a base64 encoded string.

pdf = p.html_to_pdf("html_file.htm")

Multiple instances

The library will run Chrome in the background in the remote debug mode. This means that if your project requires multiple initialized Pdfy objects, you might need to change the port used for debugging. This can be done by passing the port number to Pdfy() as follows:

p = Pdfy(debug_port=9222) #9222 is the default port

Credits

This library is released under the Apache 2.0 License.

(C) Copyright 2018-2020 Mika Hämäläinen

Cite

@software{mika_hamalainen_2020_4108770,
  author       = {Mika Hämäläinen and
                  Hiromu Hota and
                  Mike and
                  Mirza Delic},
  title        = {mikahama/pdfy 1.0.50},
  month        = oct,
  year         = 2020,
  publisher    = {Zenodo},
  version      = {1.0.50},
  doi          = {10.5281/zenodo.4108770},
  url          = {https://doi.org/10.5281/zenodo.4108770}
}

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

pdfy-1.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

pdfy-1.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pdfy-1.1.0.tar.gz.

File metadata

  • Download URL: pdfy-1.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for pdfy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ab4f5fe36215e45705a72d8b399c7aca32af0474ca6ac82670b043f1c694627a
MD5 0b01c2358b43bd094fc996cd0464cbdc
BLAKE2b-256 089fe1576c3eb308d72ebb6e368d7dd338b2b7579cf98a084bc81bdfdadfb8a2

See more details on using hashes here.

File details

Details for the file pdfy-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pdfy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for pdfy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7388b0fc1cd3d5d82f7e51f4f79eab130577df0cb601a4fc3293e0bd39ec5688
MD5 c3d5e1e14f8a912fa449dc61800c4338
BLAKE2b-256 156465af45b432475158a141b1fae4c7517a9a53a7a181f2d382bec109c99df2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page