Skip to content

Latest commit

 

History

History
208 lines (162 loc) · 4.66 KB

README.md

File metadata and controls

208 lines (162 loc) · 4.66 KB

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,
})
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",
])