Skip to main content

Simple python wrapper to convert HTML to PDF with headless Chrome via selenium.

Project description

pyhtml2pdf

Simple python wrapper to convert HTML to PDF with headless Chrome via selenium.

Install

pip install pyhtml2pdf

Dependencies

Example

Convert to PDF

Use with website url

from pyhtml2pdf import converter

converter.convert('https://pypi.org', 'sample.pdf')

Use with html file from local machine

import os
from pyhtml2pdf import converter

path = os.path.abspath('index.html')
converter.convert(f'file:///{path}', 'sample.pdf')

Some JS objects may have animations or take a some time to render. You can set a time out in order to help render those objects. You can set timeout in seconds

converter.convert(source, target, timeout=2)

Compress the converted PDF

Some PDFs may be oversized. So there is a built in PDF compression feature.

The power of the compression,

  • 0: default
  • 1: prepress
  • 2: printer
  • 3: ebook
  • 4: screen
converter.convert(source, target, compress=True, power=0)

Pass Print Options

You can use print options mentioned here

converter.convert( f"file:///{path}", f"sample.pdf", print_options={"scale": 0.95} )

Compress PDF

Use it to compress a PDF file from local machine

import os
from pyhtml2pdf import compressor

compressor.compress('sample.pdf', 'compressed_sample.pdf')

Inspired the works from,

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

pyhtml2pdf-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

pyhtml2pdf-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pyhtml2pdf-0.1.0.tar.gz.

File metadata

  • Download URL: pyhtml2pdf-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pyhtml2pdf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e2457b82535bed7a9125e03096a5766144180c2a606ae753f137ec1e2064681
MD5 628fe7fb6ca5716c6e0008ecfc808de9
BLAKE2b-256 4368ac2b28b58f81aebd17aa83d6dc92e889a207c16b95b226ff7c25990dc3b7

See more details on using hashes here.

File details

Details for the file pyhtml2pdf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyhtml2pdf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pyhtml2pdf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fee7049c0560d340ad32909c1830e3c9fdf1aaa1495b5ce41a894f3330dc990e
MD5 40182c4d8998485da5b312327538fce6
BLAKE2b-256 b432cd0389e8a137f8a82114ef3465e65e432ffa182fe4f922d0612cf5370e9e

See more details on using hashes here.

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