title: 48.wkhtml安装使用
CreateTime: 2019-07-11 00:00:48
UpdateTime: 2019-07-11 00:00:48
CategoryName: web
---
---
title: "48.wkhtml安装使用"
date: 2019-07-11T00:00:48+08:00
draft: false
tags: ["wkhtml"]
categories: ["web"]
author: "springrain"
---
## 下载安装
```shell
#安装依赖
yum install -y fontconfig libX11 libXext libXrender xorg-x11-fonts-75dpi xorg-x11-fonts-Type1
#下载:
https://wkhtmltopdf.org/downloads.html
#根据操作系统情况,选择需要的版本,这里使用
wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm
#安装rpm包
rpm -ivh wkhtmltox-0.12.5-1.centos7.x86_64.rpm
```
## 中文支持
从Windows C:\Windows\Fonts拷贝 宋体 文件simsun.ttc 到 /usr/share/fonts
目录下,这样才能正常显示中文.
## 使用
wkhtmltoimage 和 wkhtmltopdf 两个命令,把网页转成图片和pdf.
wkhtmltoimage -H 和 wkhtmltopdf -H 查看帮助
```shell
###把baidu首页输出为 jpg 图片,也可以限制大小###
wkhtmltoimage -f jpg https://www.baidu.com baidu.jpg
###带header头请求和Cookie请求###
wkhtmltoimage -f jpg --custom-header Cookie SHAREJSESSIONID=mysessionId https://www.baidu.com baidu.jpg
```
wkhtmltopdf 命令使用方法类似