Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use wkhtmltopdf, an intelligent tool for converting web pages into PDF in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use wkhtmltopdf, an intelligent tool for converting web pages into PDF in Linux, I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Wkhtmltopdf is an open source, simple and effective command line shell program that can convert any HTML (web page) into PDF documents or images (jpg, png, etc.).

Wkhtmltopdf is written in C++ and released under the General Public license (GNU/GPL). It uses the WebKit rendering engine to convert HTML pages into PDF documents without losing the quality of the pages. This is a very useful and reliable solution for creating and storing web snapshots in real time.

The function of wkhtmltopdf

Open source and cross-platform.

Use the WebKit engine to convert any HTML web page to an PDF file.

Options for adding headers and footers

Directory generation (TOC) option.

Provides batch mode conversion.

PHP or Python is supported by binding libwkhtmltox.

In this article, we will show you how to install wkhtmltopdf using the tar package on Linux systems.

Install Evince (PDF browser)

Let's install evince (a PDF reader) on the Linux system to browse the PDF file.

$sudo yum install evince [RHEL/CentOS and Fedora] $sudo dnf install evince [On Fedora 22 + versions] $sudo apt-get install evince [On Debian/Ubuntu systems]

Download the wkhtmltopdf source file

Use the wget command to download the wkhtmltopdf source file based on your Linux architecture, or you can download the * version from the wkhtmltopdf download page (currently the stable version is 0.12.4)

In 64-bit Linux systems:

$wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

In a 32-bit Linux system:

$wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz

Install wkhtmltopdf in Linux

Use the tar command to extract the file to the current directory.

-On 64-bit Linux OS-$sudo tar-xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz-On 32-bit Linux OS-$sudo tar-xvzf wkhtmltox-0.12.4_linux-generic-i386.tar.xz

To be able to execute the program from any path, install wkhtmltopdf to the / usr/bin directory.

$sudo cp wkhtmltox/bin/wkhtmltopdf / usr/bin/

How to use wkhtmltopdf?

We'll see how to convert remote HTML pages into PDF files, validate information, and use evince to browse the created files on the GNOME desktop.

Convert HTML web pages to PDF files

To convert any HTML page to PDF, run the following command. It converts the page to 10-Sudo-Configurations.pdf in the current directory.

# wkhtmltopdf http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf

Sample output:

Loading pages (1) Counting pages (2) Resolving links (4) Loading headers and footers (5) Printing pages (6) Done

Browse the generated PDF file

To verify the file you created, use the following command.

$file 10-Sudo-Configurations.pdf

Sample output:

10-Sudo-Configurations.pdf: PDF document, version 1.4

Browse the details of the generated PDF file

To browse the generated file information, run the following command.

$pdfinfo 10-Sudo-Configurations.pdf

Sample output:

Title: 10 Useful Sudoers Configurations for Setting 'sudo' in Linux Creator: wkhtmltopdf 0.12.4 Producer: Qt 4.8.7 CreationDate: Sat Jan 28 13:02:58 2017 Tagged: no UserProperties: no Suspects: no Form: none _ JavaScript: no Pages: 13 Encrypted: no Page size: 595 x 842 pts (A4) Page rot: 0 File size: 697827 bytes Optimized: no PDF version: 1.4

Browse for created files

Use evince on the desktop to view the PDF file generated by *.

$evince 10-Sudo-Configurations.pdf

Example screenshot:

It looks great in my Linux Mint 17.

Browse the web in PDF

Create the page directory for PDF (Table Of Content) (TOC)

To create a directory of PDF files, use the toc option.

$wkhtmltopdf toc http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf

Sample output:

Loading pages (1) Counting pages (2) Loading TOC (3) Resolving links (4) Loading headers and footers (5) Printing pages (6) Done

To see the TOC of the created file, use evince again.

$evince 10-Sudo-Configurations.pdf

Example screenshot:

Take a look at the picture below. It looks better than the one above.

Create a directory for web pages in PDF

Wkhtmltopdf options and use

For more information about the use and options of wkhtmltopdf, use the following help command. It shows all the available options.

Wkhtmltopdf-help after reading the above, have you mastered how to use wkhtmltopdf, an intelligent tool for converting web pages into PDF in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report