Linux安装 Wkhtmltopdf/Wkhtmltoimage

linux安装 wkhtmltopdf/wkhtmltoimage

1.安装h4cc/wkhtmltopdf

32位:

    $ composerrequireh4cc/wkhtmltopdf-i3860.12.x

    $ composerrequireh4cc/wkhtmltoimage-i3860.12.x,

64位:

    $ composerrequireh4cc/wkhtmltopdf-amd640.12.x

    $ composerrequireh4cc/wkhtmltoimage-amd640.12.x


    cp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64/usr/local/bin/

    cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64/usr/local/bin/

    chmod+x/usr/local/bin/wkhtmltoimage-amd64 

    chmod+x/usr/local/bin/wkhtmltopdf-amd64


2.安装 snappy 包:composer require barryvdh/laravel-snappy

生成配置文件

    php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"

下载pdf:

    $pdf=\PDF::loadView('chen__g',$data);

    return$pdf->download('chen__g.pdf');

渲染页面:

    $html='欢迎来到chen__g';

    $pdf=\PDF::loadHTML($html);

    return$pdf->inline();

    


导出的中英文乱码,原因是没有字体

找了windows里的宋体,最好不要用微软雅黑上传到服务器/usr/share/fonts/里参考文档:https://blog.csdn.net/hu_wen/article/details/78543645

在CentOS 4.x开始用fontconfig来安装字体库,所以输入以下命令即可:

yum -y install fontconfig

这时在/usr/shared目录就可以看到fonts和fontconfig目录了

接下来就可以给我们的字体库中添加中文字体了在CentOS中,

字体库的存放位置正是上图中看到的fonts目录,

所以我们首先要做的就是找到中文字体文件放到该目录下

(中文字体文件在我们的windows系统中就可以找到,打开c盘下的Windows/Fonts目录)

在/usr/shared/fonts目录下新建一个目录chinese:mkdir chinese

(将我们需要的字体拷贝出来并上传至linux服务器该目录之下)

修改chinese目录的权限:

chmod -R 755 /usr/share/fonts/chinese

安装ttmkfdir来搜索目录中所有的字体信息,

并汇总生成fonts.scale文件:

yum -y install ttmkfdir

然后执行:

ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir

修改字体配置文件:vi /etc/fonts/fonts.conf,

然后输入:wq保存退出

查看系统中的字体

fc-list

查看系统中的中文字体

fc-list :lang=zh

你可能感兴趣的:(Linux安装 Wkhtmltopdf/Wkhtmltoimage)