Small Node.js CLI for archiving individual WordPress posts to PDF with Playwright and Chromium.
The tool loads each post URL in a real browser, extracts the main post content and comments, removes common site chrome, expands linked gallery thumbnails to their full-size image when possible, injects a print stylesheet, and saves one PDF per post.
The repo also includes a companion CLI that discovers WordPress post URLs from a root URL.
- Node.js 18+
- Playwright Chromium installed
If Chromium is not installed yet:
npx playwright install chromiumnpm installPrint discovered post URLs, one per line:
npx wp-post-url-scraper https://your.wordpress.blog/Print discovered post URLs as JSON:
npx wp-post-url-scraper --format json https://your.wordpress.blog/Force a specific discovery method:
npx wp-post-url-scraper --source sitemap https://your.wordpress.blog/Pipe discovered URLs into the PDF archiver:
npx wp-post-url-scraper https://your.wordpress.blog/ | \
xargs npx wp-pdf-archiver --output-dir ./pdfsYou can also run discovery through the package script:
npm run discover -- https://your.wordpress.blog/Discover post URLs and archive them in one command:
npx wp-root-archiver --output-dir ./pdfs https://your.wordpress.blog/Preview the discovered URLs without generating PDFs:
npx wp-root-archiver --dry-run https://your.wordpress.blog/Archive just the first 10 discovered posts:
npx wp-root-archiver --limit 10 --output-dir ./pdfs https://your.wordpress.blog/You can also run the combined flow through the package script:
npm run archive-root -- --output-dir ./pdfs https://your.wordpress.blog/Archive one post into the current directory:
npx wp-pdf-archiver https://example.com/2024/05/interesting-post/Archive several posts into ./pdfs:
npx wp-pdf-archiver \
--output-dir ./pdfs \
https://example.com/post-one/ \
https://example.com/post-two/Use a custom print stylesheet:
npx wp-pdf-archiver \
--css ./styles/print.css \
https://example.com/gallery-post/Show help:
npx wp-pdf-archiver --helpYou can also run it through the package script:
npm run archive -- https://example.com/post-one/- Post title
- Published date when detected
- Main post body text
- Images inside the post body
- Comment threads and nested replies
The CLI rebuilds the page as a print-focused document, which strips many common WordPress chrome elements:
- Navigation
- Sidebars
- Footer widget areas
- Related post blocks
- Social/share UI
- Common ad containers
When the post contains an image thumbnail wrapped in a link to a full-size image file, the tool replaces the thumbnail source with the linked image before exporting the PDF. This helps preserve galleries that would otherwise print as small thumbnails.
- WordPress themes vary, so selector heuristics are intentionally simple and inspectable.
- If a site uses unusual markup, update
bin/wp-pdf-archiver.jsselectors or override the CSS instyles/print.css. - The generated filename is based on the detected post title.
- The URL scraper tries WordPress sitemaps first, then the REST posts endpoint, then the feed, then a light same-origin archive crawl.