### Install pyhtml2pdf
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Install the pyhtml2pdf library using pip.
```bash
pip install pyhtml2pdf
```
--------------------------------
### Convert HTML URL to PDF
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Convert a webpage from a given URL to a PDF file. Ensure Selenium Chrome Webdriver and Ghostscript are installed.
```python
from pyhtml2pdf import converter
converter.convert('https://pypi.org', 'sample.pdf')
```
--------------------------------
### Convert Local HTML File to PDF
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Convert an HTML file from your local machine to a PDF file. The file path is converted to a URI format. Ensure Selenium Chrome Webdriver and Ghostscript are installed.
```python
import os
from pyhtml2pdf import converter
path = os.path.abspath('index.html')
converter.convert(f'file:///{path}', 'sample.pdf')
```
--------------------------------
### Convert HTML to PDF with Compression
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Compress the converted PDF to reduce file size. The 'power' parameter controls the compression level, ranging from 0 (default) to 4 (screen).
```python
converter.convert(source, target, compress=True, power=0)
```
--------------------------------
### Convert HTML to PDF with Print Options
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Pass custom print options to the conversion process, such as scaling the page. Refer to the Chrome DevTools Protocol documentation for available print options.
```python
converter.convert( f"file:///{path}", f"sample.pdf", print_options={"scale": 0.95} )
```
--------------------------------
### Convert HTML to PDF with Timeout
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Set a timeout in seconds to help render dynamic content or JavaScript objects that may take time to load. This is useful for pages with animations or slow-rendering elements.
```python
converter.convert(source, target, timeout=2)
```
--------------------------------
### Compress Local PDF File
Source: https://github.com/kumaf/pyhtml2pdf/blob/master/README.md
Compress an existing PDF file from your local machine to a new file. This uses the built-in PDF compression feature of the library.
```python
import os
from pyhtml2pdf import compressor
compressor.compress('sample.pdf', 'compressed_sample.pdf')
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.