In the realm of web development and automation, capturing screenshots or generating PDFs of web pages is a common need. Whether for documentation, testing, or monitoring, having a tool that simplifies this process can be invaluable. In this blog post, we introduce a lightweight solution built with Go that leverages headless Chrome for capturing screenshots and generating PDFs.
Capture Screenshots: Take high-quality screenshots of web pages.
Generate PDFs: Create PDF documents for the web pages.
Help and Usage Information: Access help and usage information using the -h
or --help
flag.
Custom Output Path and Filename: Specify the output path and filename for captured screenshots or generated PDFs.
URL Validation: Ensure valid URLs are provided for capturing.
Output Type Validation: Validate and support output types, such as PDF or image.
File Extension Validation: Validate output filenames for proper file extensions.
To get started with the Web Page Capture Tool, you can download the pre-built binary from the GitHub repository
Download the latest binary from the Releases
wget https://github.com/GirishCodeAlchemy/WebPageCapture/releases/download/v1.0.0/web-capture-tool
Once downloaded, make the binary executable:
chmod +x web-capture-tool
Move the binary to a directory in your system’s PATH, so you can run it from any location:
sudo mv web-capture-tool /usr/local/bin/
For detailed information about the available flags and options, you can use the following command:
web-capture-tool -h
To capture a screenshot of a web page, run the following command:
./web-capture-tool <URL> image [filename]
Example:
./web-capture-tool https://example.com image output.jpg
To generate a PDF of a web page, use the following command:
./web-capture-tool <URL> pdf [filename]
Example:
./web-capture-tool https://example.com pdf output.pdf
The tool is intentionally kept minimal to serve as a foundation that can be extended based on specific requirements. Users familiar with Go can explore the code and customize the tool to suit their needs. Additionally, integrating it into existing automation pipelines or scripts is straightforward.
The Web Page Capture Tool provides a quick and efficient way to capture web pages in both image and PDF formats. Its simplicity makes it suitable for various use cases, and the underlying Go and Chrome integration offers flexibility and reliability. Whether you need to document web pages, perform visual testing, job hunting, and content documentation, or automate PDF generation, this tool can be a valuable addition to your toolkit.