Skip to main content

Simple and Fast Python framework to convert HTML files or Web Site to PDF

Project description

WebSite2PDF Logo
ExamplesDocumentationPyPiNewsChat

WebSite2PDF

Simple and Fast Python framework to convert HTML files or Web Site to PDF

Installing with pip

pip3 install WebSite2PDF

or

pip3 install git+https://github.com/uNickz/WebSite2PDF

Installing with python

python3 -m pip install WebSite2PDF

or

python3 -m pip install git+https://github.com/uNickz/WebSite2PDF

Dependencies

Example

Using a url

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client()
with open("file_name.pdf", "wb+") as file:
    file.write(c.pdf(url))

or

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client()
c.pdf(url, filename = "file_name.pdf")

Using a file HTML

import WebSite2PDF

file_path = "C:\Users\uNickz\index.html"

c = WebSite2PDF.Client()
with open("file_name.pdf", "wb+") as file:
    file.write(c.pdf(f"file:///{file_path}"))

or

import WebSite2PDF

file_path = "C:\Users\uNickz\index.html"

c = WebSite2PDF.Client()
c.pdf(f"file:///{file_path}", filename = "file_name.pdf")

Using multiple urls or files HTML

import WebSite2PDF

urls_or_path = ["https://pypi.org", "file:///C:\Users\uNickz\index.html", "https://github.com/"]

c = WebSite2PDF.Client()
c.pdf(urls_or_path, filename = ["pypi.pdf", "index.pdf", "github.pdf"])

or

import WebSite2PDF

urls_or_path = ["https://pypi.org", "file:///C:\Users\uNickz\index.html", "https://github.com/"]
file_name = ["pypi.pdf", "index.pdf", "github.pdf"]

c = WebSite2PDF.Client()
data = c.pdf(urls_or_path)
for name, data in zip(name, data):
    with open(name, "wb+") as file:
        file.write(data)

Using a delay (in seconds) before create PDF

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client()
c.pdf(url, filename = "file_name.pdf", delay = 3)

Using global PDF Options

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client(
    pdfOptions = {
        "landscape" = True,
        "displayHeaderFooter": True,
        "printBackground": True,
        "preferCSSPageSize": True,
    }
)
c.pdf(url, filename = "file_name.pdf")

Using specific PDF Options for a PDF

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client(
    pdfOptions = {
        "landscape" = True,
        "displayHeaderFooter": True,
        "printBackground": True,
        "preferCSSPageSize": True,
    }
)
c.pdf(url, filename = "file_name.pdf", pdfOptions = {
    "landscape" = False,
    "displayHeaderFooter": True,
})

Using global Selenium ChromeDriver Options

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client(
    pdfOptions = {
        "landscape" = True,
        "displayHeaderFooter": True,
        "printBackground": True,
        "preferCSSPageSize": True,
    }, seleniumOptions = [
        "--no-sandbox",
        "--headless",
    ]
)
c.pdf(url, filename = "file_name.pdf")

Using specific Selenium ChromeDriver Options for a PDF

import WebSite2PDF

url = "https://pypi.org"

c = WebSite2PDF.Client(
    pdfOptions = {
        "landscape" = True,
        "displayHeaderFooter": True,
        "printBackground": True,
        "preferCSSPageSize": True,
    }, seleniumOptions = [
        "--no-sandbox",
        "--headless",
    ]
)
c.pdf(url, filename = "file_name.pdf", pdfOptions = {
        "landscape" = False,
        "displayHeaderFooter": True,
    }, seleniumOptions = [
        "--no-sandbox",
        "--disable-gpu",
])

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page