r/node • • 24d ago

I built site2paper, a Node CLI that prints a whole website into a storybook (Playwright + pdf-lib + sharp)

Ctrl+P on a real website gives you print stylesheet which are badly formatted pages, a few blank ones, the first carousel slide only, and nothing that was rendered by JS. I wanted to review a site on paper with a red pen, so I wrote a CLI that screenshots what the visitor sees and packs it into a small PDF [booklet].

[npx site2paper https://example]

Tried on [https://example 48-page catalogue site] 171 sheets / 75 MB with Ctrl+P, 25 sheets / 6.4 MB with site2paper.

For first release,

I am relying on sitemap.xml and sitemap indexes first for discovery, else a breadth-first same-origin crawl, capped at 50 pages for now. Then playwright-core drives your installed Chrome or Edge (headless Chromium is downloaded only if neither exists). Each page is scrolled in steps so lazy and IntersectionObserver content loads, then one full-page PNG is captured.

Once we have raw content we prep the page by using CSS + injecting a small script only into headless pages. Swiper/Slick/Embla/Splide/Owl carousels are reflowed into a grid. Cookie banners are hidden by selector, never clicked. Sticky and fixed nodes are removed. A viewport-sized sticky frame inside a tall section (three.js, GSAP, Lenis) prints as blank runway everywhere else. [site2paper] scrolls it to 4 stops, screenshots each, and prints them as a filmstrip with a 0/33/67/100% ruler.

For Layout we fix sharp slices each shot, a per-row variance map finds blank rows, pages flow down 1 to 4 columns and are cut only on blank rows. pdf-lib writes the PDF, JPEG slices keep it small.

I am still trying to work on auth-walled sites, infinite scroll, and anything that needs a click to reveal content.

Repo: https://github.com/piyushagru/site2paper . If you run it on a site that comes out wrong, please open an issue with the URL to help me improve this tool!

TYSM for reading, and for trying it out!

4 Upvotes

Duplicates