Convert a website (URL) or a local HTML file into a PDF.
- URL or local HTML input
- Config file (TOML) + CLI overrides
- Uses Chromium via Playwright (good fidelity)
- Common PDF options: page size, margins, orientation, scale, background graphics
- Optional wait strategies for dynamic sites
- GUI version (Windows-friendly)
- Login/restricted pages support (storage state / cookies / basic auth / interactive login)
python -m pip install -U pip
python -m pip install -e .
python -m playwright install chromiumRun the GUI:
web2pdf-gui- Run an interactive login once and save session:
web2pdf convert "https://site.example.com/protected" --interactive-login --save-storage-state-to .\state.json -o first.pdf- Next runs reuse the saved session:
web2pdf convert "https://site.example.com/protected" --storage-state .\state.json -o out.pdfExport cookies using a browser extension that outputs Netscape cookies.txt, then:
web2pdf convert "https://site.example.com/protected" --cookies-txt .\cookies.txt -o out.pdfweb2pdf convert "https://site.example.com/protected" --basic-auth-user USER --basic-auth-password PASS -o out.pdfThis produces dist\web2pdf\web2pdf.exe.
cd C:\Users\marti\Desktop\web2pdf
# Ensure browsers are installed BEFORE building, so they can be bundled
python -m playwright install chromium
python -m pip install -e .[build]
pyinstaller .\web2pdf.specThis project is set up so the built exe can run without downloading browsers:
- During the build, your local Playwright cache (usually
%LOCALAPPDATA%\ms-playwright) is copied into the dist folder. - At runtime (inside the exe), we set
PLAYWRIGHT_BROWSERS_PATH=0so Playwright looks for a bundled.local-browsersfolder near its driver.
If you want to override this behavior, set one of these environment variables before running:
PLAYWRIGHT_BROWSERS_PATH(custom browser location)PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0(allow downloads)
Convert a URL:
web2pdf "https://example.com" -o example.pdfConvert a local HTML file:
web2pdf ".\page.html" -o page.pdfUse a config file:
web2pdf "https://example.com" -c .\web2pdf.toml -o out.pdfCopy web2pdf.example.toml to web2pdf.toml and tweak.
Precedence: CLI flags > config file > defaults.
- If you built the exe but it can’t find Chromium, make sure you ran
python -m playwright install chromiumbeforepyinstaller .... - For corporate proxies/firewalls, you may need to preinstall the browsers on the build machine.
- Some sites never become "networkidle" and will time out or behave flaky. Try:
web2pdf "https://www.alza.cz/" -o alza.pdf --timeout-ms 90000 --wait-until domcontentloaded --wait-until-fallbacks load --post-wait-ms 1500This tool renders pages headlessly. Some sites block headless browsers; try adjusting the user-agent or adding extra headers/cookies.
Security note: be careful with storing credentials (basic auth, cookies, storage state). Treat state.json and cookies files like passwords.