当前位置:网站首页>This artifact is highly recommended. One line command will convert the web page to PDF!
This artifact is highly recommended. One line command will convert the web page to PDF!
2022-06-11 03:57:00 【Python Technology】

writing | Leisure and joy
source :Python technology 「ID: pythonall」

In daily work and life , We often encounter a need : Save the page as PDF.
such as , I prefer an article on a official account , To prevent articles from being deleted , I want to save this historical article of the official account as PDF file , Put it in your local hard drive , You can show it at any time .
The method I used before is the function of the browser , Using shortcut keys Ctrl + P Or right click on the page in the browser , And then choose “ Print ” Options , Call up the browser print function .

And then “ The printer ” Options “ Save as PDF”, You can output PDF The file .
This process takes a long time , It is possible to operate individual pages occasionally , If there are more pages, you will be more anxious .
I found a useful tool by accident today , It only needs one line of command to realize web page conversion PDF file save .
This artifact is ——wkhtmltopdf!
install
To use wkhtmltopdf , You need to install this software first .
wkhtmltopdf Its official website is :https://wkhtmltopdf.org/
On the official website Downloads Under navigation , We can see that this software supports multiple operating systems , Select the installation file corresponding to the operating system you are using .

Here's what I downloaded windows edition , Once the download is complete , Direct installation . The installation process is relatively simple , Only a few steps in total , Just configure it by default .
Use
Page to PDF
After the software is installed , You can use it .
Take Baidu home page as an example , Show how to save Baidu homepage as PDF file .
We turn on the terminal , Find... In the installation path bin Catalog , My computer path is like this :

Then type the command :
.\wkhtmltopdf.exe https://baidu.com C:\baidu.pdf
Run this command , Wait for the run to complete , You can find it in the specified directory baidu.pdf The file , I am here C Under the root directory .

This is not limited to the pages on the website , The local html Documents are also available , You just need to https://baidu.com Replace it with your local web path .
here , You need to enter the installation directory of the software to run the command , More trouble . You can put the software's bin Directory added to environment variables , After adding, it can be opened and used in the terminal .
Web page to picture
wkhtmltopdf Not only can the web page be transferred to PDF file save , You can also save web pages as pictures , Just use another command :
.\wkhtmltoimage.exe https://baidu.com C:\baidu.png
similarly , Wait for the command to run , You can find it in the corresponding directory baidu.png Pictures. .

summary
wkhtmltopdf Is very simple to use , Even the official website introduces its usage in a few words . Based on this tool , We may be able to do more , For example, call this script command , Turn the web pages crawled down by the crawler into PDF Or picture saving , This is for you to explore and use !
PS: Reply within company number 「Python」 You can enter Python Novice learning communication group , Together 100 Day plan !
Old rules , Brothers, remember , Right lower corner “ Looking at ” click , If you think the content of the article is good , Remember to share the circle of friends and let more people know !

【 Mystery gift bag Access method 】
Identify the QR code at the end of the text , reply :1024

边栏推荐
- Student online education and teaching course management system based on SSM framework
- 给孩子的国学经典
- Quartz: an old and robust open source task scheduling framework, which is smooth enough to use
- Build local source 2.0 for Galaxy Kirin server version
- [cnn]| translation invariance
- 密码找回功能可能存在的问题(补充)
- Host computer development (how to develop host computer)
- Interface performance optimization ideas
- ImportError: DLL load failed while importing _ Sqlite3: the specified module could not be found
- 代码复现CSRF攻击并解决它
猜你喜欢
![[elt.zip] openharmony paper Club - electronic device software update compression](/img/d8/0a6beafc9b986f6fc61411ba09c4a2.png)
[elt.zip] openharmony paper Club - electronic device software update compression

MAUI 遷移指南

A Security Analysis Of Browser Extensions

How to improve the efficiency of regression testing

Detailed explanation of scenario method for common test case design methods

Detailed explanation of network time synchronization (NTP network timing) of video monitoring system

编程大作战 -- 挑战高考题

WPF of open source project hero alliance

OpenGL error Guide

Maui migration guide
随机推荐
Docker swarm installing MySQL Cluster
[interpretable] | axiomatic attribute for deep networks
Two solutions for reliable message consistency
NTP time server (GPS Beidou satellite synchronous clock) application boiler monitoring system
pmm监控oracle
After the college entrance examination, what can I do and how should I choose my major-- From the heart of a college student
Comparison of four delivery modes of Message Oriented Middleware
Composition and configuration of GPS Beidou clock synchronization (satellite time synchronization system) in power plant
OPENSSL ASN. 1, DER, PEM, X509
JS the most commonly used sorting - hand tearing JS series
SSL library selection
BP神经网络C语言实现总结
Market prospect analysis and Research Report of modular lithium ion battery in 2022
Sentence s, paragraph P in VIM text object
让人感到心灵平静,阳光温暖的图片
Path count 2 (DP + number of combinations)
After the installation of Damon database is completed, query whether it is case sensitive
6. 表格标签
[dataset] | UAV Perspective
Quel genre de personne est heureuse?