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 install and use wkhtmltopdf in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how to install and use wkhtmltopdf in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Wkhtmltopdf is a tool developed using the WebKit web page rendering engine to convert HTML documents into PDF documents, which can be integrated with a variety of scripting languages to convert documents.

Wkhtmltopdf is open source and cross-platform. Use the WebKit engine to convert any HTML web page to an PDF file. Add options for header and footer catalog generation (TOC) options. 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 schema, or you can download the latest version from the wkhtmltopdf download page (currently the latest 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 installs 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.

How does $sudo cp wkhtmltox/bin/wkhtmltopdf / usr/bin/ 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 LinuxCreator: wkhtmltopdf 0.12.4Producer: Qt 4.8.7CreationDate: Sat Jan 28 13:02:58 2017Tagged: noUserProperties: noSuspects: none_JavaScript: noPages: 13Encrypted: noPage size: 595 x 842 pts (A4) Page rot: 0File size: 697827 bytesOptimized: noPDF version: 1.4

Browse for created files

Use evince on the desktop to view the newly generated PDF file.

$evince 10-Sudo-Configurations.pdf

Example screenshot: it looks great in my Linux Mint 17.

Create the directory of the page for PDF

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.

An intelligent tool for converting web pages into PDF in Linux an intelligent tool for converting web pages into PDF in Linux

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

Thank you for reading! This is the end of the article on "how to install and use wkhtmltopdf in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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

Development

Wechat

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

12
Report