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

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.

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 Mika Hämäläinen

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.0.20.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

pdfy-1.0.20-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdfy-1.0.20.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.13.0 setuptools/18.5 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.10

File hashes

Hashes for pdfy-1.0.20.tar.gz
Algorithm Hash digest
SHA256 894c4e67e68fa40474c9052b2cbd79ec6570057f25137b5bc75df10acae249cc
MD5 e671825f757aece1aaddad458fbb2c1f
BLAKE2b-256 829efcec650e2a582adad21734bbad2e9ff8d9d55c6d4d590841eae60848a00a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfy-1.0.20-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.13.0 setuptools/18.5 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.10

File hashes

Hashes for pdfy-1.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 2f6c13086637bc3ab080eb7a1661c7a47c38bf58e4d4a1a2b238dde1a2042d9c
MD5 4f9c19ee2f9b567596c89a7259a2eaac
BLAKE2b-256 4df8bb615cefd91a35b41d691b3c03a8f247b8855c8a2607a0344fde2c60378a

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