wkhtmltopdf is an open source command-line tool that can save web pages as a PDF or an image
SingleFile, its fork SingleFileZ and Save Page WE are excellent options to save entire webpages as a single HTML page. But sometimes, you may want the web page to be easily accessible. For example, you may want to have your study materials, research papers on your phone and computer. Converting the HTML to a PDF is a good way to ensure cross-device compatibility,
Wkhtmltopdf is an open source and cross-platform tool that can convert HTML pages to PDF. This is a command-line utility, but don't worry, it's pretty easy to use.
Install the application or extract the portable archive to a folder. Open a command prompt window.
The syntax for using the tool is fairly simple, enter the name wkhtmltopdf, followed by the URL of the web page, and the name of the PDF that you want to create, like so.
wkhtmltopdf URL filename.pdf
Let's say you want to save a copy of a website, this is what the command will look like.
wkhtmltopdf https://www.example.com/page example.pdf
That wasn't difficult now, was it? But I would recommend using a slightly different command.
wkhtmltopdf -n https://www.example.com/page example.pdf
When the command is passed to the program, it loads the web page in the background (without opening your browser), and begins the conversion process. This may take a minute or two depending on the webpage's content, but it does not require any interaction. So, just to wait for it to complete and your PDF is ready to use. wkhtmltopdf saves the PDF in its own folder. You should pay attention to the PDF name that you're using, because the program will overwrite any existing file in the folder without warning you about it.
Here's a screenshot of a web page opened in Firefox.
Let's use the tool. wkhtmltopdf https://en.wikipedia.org/wiki/Computer wiki.pdf
And here's what the PDF version of it (created using wkhtmltopdf) looks like.
As you can see from the picture, wkhtmltopdf extracted the page perfectly. It also preserves links on pages.
There are a ton of other options that you can use, you can view them by using the built-in help command.
If you only want the text from the webpage, you can add --no-images to the command. Don't want links (to other pages) to be included? Use --disable-internal-links
What if what you want to save the HTML file as an image? Why not, you can do that with the help of wkhtmltoimage. This utility is included as part of the wkhtmltox package. You can use the same commands that you used for the PDF, with the image tool.
wkhtmltoimage https://en.wikipedia.org/wiki/Computer wiki.jpg
It also supports other image formats such as PNG, BMP, but these end up with really large file sizes (100+ MB), JPG has the best compression level.
Wkhtmltopdf and wkhtmltoimage are available for Windows, Mac, Linux. The tool comes in portable versions for 32-bit and 64-bit systems.