PHP 打印网页 输出 pdf,image 调用wkhtmltopdf/ WkHtmlToImage

目前只在windows/linux测试,安装 WkHtmlToPdf/WkHtmlToImage工具,如转换过程出现乱码,请安装相应中文字体 下载地址:http://code.google.com/p/wkhtmltopdf/

function convert($type='pdf')

        {

            $filename=time();

            $url=$this->input->get("url");

            if($type=='pdf')

            {

                $filename="upload/tmp/".$filename.".pdf";

                exec("/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");

        }

//以下测试代码

 

$result = exec("e:\\wkhtmltopdf\\wkhtmltopdf.exe -O Landscape \"http://127.0.0.1:89/index.php?app=detail&action=detail_pdf&id=200\" vish.pdf",$out,$status);// $result = shell_exec('"e:\\wkhtmltopdf\\wkhtmltopdf.exe" "http://127.0.0.1/?app=detail&action=detail_pdf&id=220" vish.pdf 2>> err3.txt 1>> out3.txt');echo $result;$file = "vish.pdf";$pdf = file_get_contents("vish.pdf");header('Content-Type: application/pdf');header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1header('Pragma: public');header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the pastheader('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');header('Content-Length: '.strlen($pdf));header('Content-Disposition: inline; filename="'.basename($file).'";');ob_clean(); flush(); echo $pdf;

转载于:https://my.oschina.net/osgrace/blog/712141

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值