使用PHP WkHtmlToPdf/WkHtmlToImage 将网页直接转换成pdf或图片

function convert($type='pdf')
        {
            $filename=time();
            $url=$this->input->get("url");
            if($type=='pdf')
            {
                $filename="F:/upload/tmp/".$filename.".pdf";
                exec("F:/home/phptool/wkhtmltopdf-i386 $url $filename");
                header('Content-Type: application/pdf');
            }
            elseif($type=='image')
            {
                $filename="upload/tmp/".$filename.".jpg";
                exec("/home/phptool/wkhtmltoimage-i386 $url $filename");
                header('Content-Type: image/jpeg');
            }
            header('Pragma: public');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Content-Transfer-Encoding: binary');
            header('Content-Length: '.filesize($filename));
            readfile("$filename");
 }

 需要注意的是,如果有的字体没有显示,那么需要在服务器中安装字体,安装字体的方法请阅读:http://www.cnblogs.com/lhm166/articles/7235003.html

wkhtmltox   LINUX插件下载地址:http://pan.baidu.com/s/1qYFh0c8

posted @ 2017-07-25 16:47  智昕  阅读(843)  评论(0编辑  收藏  举报