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 transfer HTML to PDF

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to PDF from HTML to PDF". In daily operation, I believe many people have doubts about how to convert HTML to PDF. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how to convert HTML to PDF". Next, please follow the editor to study!

Introduction to the tool "wkhtmltopdf"

The full name of the tool is "wkhtmltopdf"; it is a command line tool that uses the Qt WebKit engine to render html documents into pdf documents or images (image). (to emphasize: it is a "command line tool")

Supports multiple platforms and can run under systems such as win,linux,os x.

Advantages

When you generate PDF, it will automatically generate a tree directory structure based on your H tag in the HTML page.

The utility model is compact and convenient, and the conversion speed is fast.

Cross-platform, used in Liunx, can also be used in win (I have only used it on these two platforms).

Preparation before use

Be sure to download and install it before using it. There may be situations where you need to set environment variables for different operating systems. If you execute wkhtmltopdf-V on the command line after installation, prompt for the following message:

C:\ Users\ hehe > wkhtmltopdf-V 'wkhtmltopdf' is not an internal or external command, nor a runnable program or batch file.

This means that you need to configure the environment variable of the system, and add the bin subdirectory under your installation wkhtmltopdf directory to the PATH environment variable as appropriate.

I am using a win system, and I installed it in the wkhtmltopdf directory on disk D, so I need to add the D:\ wkhtmltopdf\ bin directory to the environment variable PATH

When you execute wkhtmltopdf-V after the correct installation, you will be prompted as follows:

C:\ Users\ wfso > wkhtmltopdf-Vwkhtmltopdf 0.12.3.2 (with patched qt)

Looking at the information above, we can see that when I wrote this article, the version of wkhtmltopdf installed in my system was 0.12.3.2.

Start using

Command format: wkhtmltopdf [GLOBAL OPTION]... [OBJECT]...

Command-line tools naturally have no graphical interface.

Just looking at the above command format does not seem to be very simple to understand how to use ah, don't worry, the following will be described in detail, but in order to meet some impatience, I will first give a few examples below. Shoushantang can be used directly, and students who don't want to know more about it don't have to waste any more time.

Convert a html file to PDF

Command format: wkhtmltopdf xxx.html xxx.pdf

D:\ MyWorkSpace\ markdown > wkhtmltopdf 1.html 1.pdfLoading pages (1) Counting pages (2) Resolving links (4) Loading headers and footers (5) Printing pages (6) Done

When you see something similar to the above, say that the conversion is complete, open the converted pdf document and study it slowly.

Convert a web page pointed to by url into PDF

Command format: wkhtmltopdf url xxx.pdf

D:\ MyWorkSpace\ markdown > wkhtmltopdf www.yioks.com yioks.pdfLoading pages (1 to 6) QFont::setPixelSize: Pixel size

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