opensourceprojects.dev

A broadsheet for software that doesn't ask for your email

A CLI that crawls a site and turns every page into a PDF
GitHub RepoImpressions2

Project Description

View on GitHub

Turn Any Website Into a Stack of PDFs With One Command

You've probably been there: you find a documentation site or a multi-page tutorial you want to keep offline, and your options are either printing each page manually or copy-pasting everything into a document that immediately loses all its formatting. Web2pdf is a command line tool that takes a starting URL, crawls the site, and converts every page it finds into a formatted PDF—so you end up with a clean, navigable archive instead of a bookmark graveyard.

What It Does

Web2pdf is a CLI tool that converts webpages into PDFs. You give it a URL, and it handles the conversion from there. The core feature is recursive crawling: point it at a single starting page, set a configurable depth, and it'll follow same-domain links and convert what it finds. There's also batch conversion if you already know which pages you want and just need them processed in one go.

Under the hood, it uses WeasyPrint for the actual PDF rendering, which is why the installation instructions spend so much time on system dependencies—Cairo, Pango, and friends need to be present before the Python packages will work. The output isn't just a raw dump of HTML either. You get a set of formatting controls: custom CSS for styling, support for multi-column layouts, automatic page numbers, a table of contents generated from your headings, and explicit page break control. Link filtering keeps the crawler from wandering off to external sites, which is a small detail but a meaningful one if you've ever watched a naive spider eat your bandwidth.

Why It's Cool

  • Recursive crawling with sane defaults. The smart link filtering means you don't have to babysit the crawl. It sticks to the same domain, which is exactly what you want for archiving a docs site or a blog.

  • Real formatting control, not just "print to PDF." The combination of page breaks, table of contents generation, and multi-column support puts this closer to a small document pipeline than a one-off converter. If you're building internal reports or offline reference material, those controls matter.

  • CSS customization is the escape hatch. Because you can inject your own CSS, you're not stuck with whatever the site's print stylesheet happens to do. You can restyle fonts, colors, backgrounds—whatever the layout needs.

  • Conda is the recommended path. The README is upfront that system dependencies must be installed before creating the conda environment, and it even calls out the order mattering. That's the kind of honesty you appreciate after you've already created the environment and have to blow it away.

  • It knows where it ends. The README also points to a managed service (DocuQueue) for production use cases that need scaling and templates. Not every open-source tool is honest about its boundaries, and this one is.

How to Try It

Start by cloning the repo:

git clone https://github.com/dvcoolarun/web2pdf.git

Then install the system dependencies for your platform. On macOS with Homebrew:

brew install cairo pango gdk-pixbuf libffi pkg-config

On Ubuntu or Debian:

sudo apt-get update && sudo apt-get install -y \
    build-essential \
    python3-dev \
    libffi-dev \
    libssl-dev \
    libxml2-dev \
    libxslt1-dev \
    libjpeg-dev \
    libpango1.0-dev \
    libcairo2-dev \
    libgirepository1.0-dev \
    gobject-introspection

Fedora, RHEL, and CentOS users have a dnf equivalent in the README. Once the system libraries are in place, the recommended setup is conda:

conda env create -f environment.yml
conda activate web2pdf
python main.py

One gotcha worth flagging: if you're on macOS and hit a "cannot load library 'libgobject-2.0-0'" error after installing everything, WeasyPrint probably can't find the libraries. The README suggests setting DYLD_LIBRARY_PATH and PKG_CONFIG_PATH in your shell config to point at /opt/homebrew/lib. That's a common enough snag that it's worth checking before you assume something's broken.

The full instructions and troubleshooting notes live at github.com/dvcoolarun/web2pdf.

Final Thoughts

Web2pdf is a focused tool that does one job and gives you enough knobs to make the output actually usable. It's best suited for developers who need offline archives of documentation, internal reference material, or multi-page content they want to keep in a stable format. The dependency setup is the main friction point—WeasyPrint's system libraries aren't trivial on a fresh machine—but the conda workflow and the troubleshooting section make it manageable. If you've been looking for a scriptable way to turn a site into a formatted PDF collection, this is a solid place to start.

Back to Projects
Project ID: 87af5bdc-c963-4db0-ac06-8f3310fe0999Last updated: September 23, 2026 at 02:48 AM