Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pyhtml2pdf

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyhtml2pdf

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

  • 0.0.7
  • PyPI
  • Socket score

Maintainers
1

pyhtml2pdf

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

Install

pip install pyhtml2pdf

Dependencies

  • Selenium Chrome Webdriver (If Chrome is installed on the machine you won't need to install the chrome driver)
  • Ghostscript

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,

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc