Jump to content

(Guide/Review) wkhtmltopdf is an open source command-line tool that can save web pages as a PDF or an image


Karlston

Recommended Posts

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

 

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

The only difference here is the -n switch, which disables Javascript from loading. It also speeds up the process of the PDF creation. You can also use --disable-javascript for the same effect, but using -n is much simpler. If a page has a lot of scripts, the conversion process might get stuck, and sometimes the output file's appearance could also be affected, but if you want a quick processing, -n is your best option. You can run it without the parameter if the output is garbled.

 

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.

 

wkhtmltopdf is an open source command-line tool that can save web pages as a PDF or an image

 

Here's a screenshot of a web page opened in Firefox.

 

original webpage

 

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.

wkhtmltopdf version of the webpage

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.

wkhtmltopdf -h

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

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.

 

wkhtmltoimage file size

 

Wkhtmltopdf and wkhtmltoimage are available for Windows, Mac, Linux. The tool comes in portable versions for 32-bit and 64-bit systems.

 

Landing Page: https://github.com/wkhtmltopdf/wkhtmltopdf

 

 

wkhtmltopdf is an open source command-line tool that can save web pages as a PDF or an image

Link to comment
Share on other sites


  • Views 988
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...