ubuntu下使用imgkit的坑

使用系统是ubuntu 16

第一部分:

首先是imgkt的安装:

pip install imgkit

然后是wkhtmltopdf的安装,不要使用 apt-get安装!!因为apt-get安装的是一个阉割版!在文档中有写道:

Warning! Version in debian/ubuntu repos have reduced functionality (because it compiled without the wkhtmltopdf QT patches), such as adding outlines, headers, footers, TOC etc. To use this options you should install static binary from wkhtmltopdf site or you can use this script.

正确的使用方式是创建 init.sh文件,将以下内容拷贝进去:

#!/usr/bin/env bash

sudo apt-get install -y openssl build-essential xorg libssl-dev xvfb
pip install coverage
wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
cd wkhtmltox
sudo chown root:root bin/wkhtmltopdf
sudo cp -r * /usr/

然后运行 bash init.sh   即可成功安装所有包。

第二部分:

关于imgkit不能读取中文内容,一般是缺少字体造成的。

首先下载SimSun.ttf文件  (在网上一搜就可以了)

然后把文件放到unbuntu系统的 /usr/share/fonts 目录下。同时,在html文本的标签下添加字体设置。

    

 

你可能感兴趣的:(ubuntu下使用imgkit的坑)