One of the easiest way to screen capture a particular web page as a PNG image is by using CutyCapt, which is a convenient command line Linux tool for converting any HTML webpage to a variety of vector and bitmat image formats (e.g., SVG, PDF, PS, PNG, JPEG, TIFF, GIF). Internally, CutyCapt uses WebKit rendering engine to export webpage rendering output to an image file. Built with Qt, CutyCapt is actually a cross-platform application available for other platforms such as Windows as well.
In this tutorial, I will describe how to convert an HTML web page to PNG image format using CutyCapt.
Install CutyCapt on Linux
Here are distro-specific instructions to install CutyCapt on Linux.
Install CutyCapt on Debian, Ubuntu or Linux Mint
Install CutyCapt on Fedora
$ svn co svn://svn.code.sf.net/p/cutycapt/code/ cutycapt
$ cd cutycapt/CutyCapt
Before compilation on Fedora, you need to patch source code.
Open CutyCapt.hpp with a text editor, and add the following two lines at the beginning of the file.
#include <QNetworkReply> #include <QSslError>
Finally, compile and install CutyCapt as follows.
$ sudo cp CutyCapt /usr/local/bin/cutycapt
Install CutyCapt on CentOS or RHEL
First enable EPEL repository on your Linux. Then follow the same procedure as in Fedora to build and install CutyCapt.
Convert HTML to PNG with CutyCapt
To take a screenshot of an HTML page as a PNG image, simply run CutyCapt in the following format.
To save an HTML page to a different format (e.g., PDF), simply specify the output file appropriately.
The following shows command-line options of cutycapt.
Convert HTML to PNG with CutyCapt on a Headless Server
While CutyCapt is a CLI tool, it requires an X server running. If you attempt to run CutyCapt on a headless server, you will get the error:
cutycapt: cannot connect to X server :0
If you want to run CutyCapt on a headless server without X windows, you can set up Xvfb (lightweight "fake" X11 server) on the server, so that CutyCapt does not complain.
To install Xvfb on Debian, Ubuntu or Linux Mint:
To install Xvfb on Fedora, CentOS or RHEL:
After installing Xvfb, proceed to run CutyCapt as follows.
It will launch Xvfb server first, and then use CutyCapt to screen capture the webpage. So it may take longer. If you want to make multiple screenshots, you may want to start Xvfb server as a background daemon beforehand.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!