Giter VIP home page Giter VIP logo

pyhtml2pdf's Introduction

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,

pyhtml2pdf's People

Contributors

klius avatar kumaf avatar maxvst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.