A command-line tool written in Go that converts web pages to PDF files. It supports batch processing of URLs and can automatically extract URLs from an index page.
It's simply a wrapper around chromedp to generate PDFs.
- Convert single or multiple URLs to PDF
- Extract URLs from an index page
- Customizable PDF scaling
- Parallel processing of URLs
- Custom output directory
- Optional filename prefix
- Support for query parameters
- Landscape orientation
- Background graphics included
- Go 1.16 or higher
- Chrome/Chromium browser (required for headless PDF generation)
go get github.com/petermunro/url2pdf# Clone the repository
git clone https://github.com/petermunro/url2pdf.git
cd url2pdf
# Build the binary
go build -o url2pdf
# Optional: install to $GOPATH/bin
go installgo run main.go [flags]-urls: Comma-separated list of URLs to convert-index: URL of the directory index page (alternative to -urls)-output: Directory to save PDFs (default: "pdfs")-scale: Scale of the webpage rendering (between 0.1 and 2.0, default: 1.0)-prefix: Prefix to add to output filenames-portrait: Print in portrait mode (default is landscape)-query: Query parameter to append to URLs (e.g. 'print=true')
Convert a single URL:
go run main.go -urls "https://example.com/page.json"Convert multiple URLs:
go run main.go -urls "https://example.com/page1.json,https://example.com/page2.json"Process URLs from an index page:
go run main.go -index "https://example.com/index" -query "print=true"Customize output:
go run main.go -urls "https://example.com/page.json" -output "my-pdfs" -scale 1.2 -prefix "doc"PDFs are saved to the specified output directory (default: "pdfs"). Filenames are generated from:
- The last segment of the URL (for .json URLs)
- MD5 hash of the full URL (for other URLs)
- The program logs errors for individual URL processing failures but continues with remaining URLs
- Invalid scale values (outside 0.1-2.0) will cause the program to exit
- Missing required flags (-urls or -index) will cause the program to exit