Notice (8): file_put_contents(): Write of 272 bytes failed with errno=28 No space left on device [CORE/src/Log/Engine/FileLog.php, line 140]

Notice: file_put_contents() [function.file-put-contents]: Write of 1108 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 5131 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3151 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 284 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2558 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 5437 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3151 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 3642 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3514 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 23878 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3155 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): 1hours cache was unable to write '4c14dd13594b0672c724442467d02575' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2950 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 32575 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2792 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): 1hours cache was unable to write '3be9a61ce9967e5b5808421a41914665' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2587 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 23878 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3248 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): 1hours cache was unable to write '4c14dd13594b0672c724442467d02575' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 3043 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 106089 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2886 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): 1hours cache was unable to write 'e417c3ded1ce6564f78e6fb05702db87' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2680 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
PHP实现HTML生成PDF文件的方法 - 站长搜索
首页 > 资讯列表 > 编程/数据库 >> PHP

PHP实现HTML生成PDF文件的方法

PHP 2014-12-01 12:10:29 转载来源: 网络整理/侵权必删

本文是一个PHP实现的可以把HTML生成PDF文件的方法示例代码,可实现linux中利用HTML2FPDF与wkhtmltoimage把网页html直接生成pdf格式的文件,需要的朋友可以参考下 找到一款在FPDF和HTML2FPDF源码基础上开发的一套开源程序,作者很给力。基本解决了中文(以及日语、韩语及东南亚和全球语言)乱码的问题,在Windows/Linux开发环境下测试可用,不需要安装别的组件支持,是没有VPS和独立服务器的网站开发者的福音

本文是一个PHP实现的可以把HTML生成PDF文件方法示例代码,可实现linux中利用HTML2FPDF与wkhtmltoimage把网页html直接生成pdf格式的文件,需要的朋友可以参考下

找到一款在FPDF和HTML2FPDF源码基础上开发的一套开源程序,作者很给力。基本解决了中文(以及日语、韩语及东南亚和全球语言)乱码的问题,在Windows/Linux开发环境下测试可用,不需要安装别的组件支持,是没有VPS和独立服务器的网站开发者的福音。

不多说,源码名称是MPDF,官方地址是:http://www.mpdf1.com/ 已经更新到5.6版。
到官网下载,解压到网站目录下,使用。

<?php
include('mpdf.php');
$mpdf=new mPDF('UTF-8','A4','','',15,15,44,15);
$mpdf->useAdobeCJK = true;
$mpdf->SetAutoFont(AUTOFONT_ALL);
$mpdf->SetDisplayMode('fullpage');
//$mpdf->watermark_font = 'GB';
//$mpdf->SetWatermarkText('中国水印',0.1);
$url = 'http://www.phperz.com/';
$strContent = file_get_contents($url);
//print_r($strContent);die;
$mpdf->showWatermarkText = true;
$mpdf->SetAutoFont();
//$mpdf->SetHTMLHeader( '头部' );
//$mpdf->SetHTMLFooter( '底部' );
$mpdf->WriteHTML($strContent);
$mpdf->Output('ss.pdf');
//$mpdf->Output('tmp.pdf',true);
//$mpdf->Output('tmp.pdf','d');
//$mpdf->Output();
exit;
?>


PASS:需要注意的是,PHP文件要是UTF-8。不用心情天空贴出的代码,自己写时出现方格乱码时,可以在config.php文件里的$this->useAdobeCJK = false;修改成true或者必须标注:$mpdf->useAdobeCJK = true; 官方有文档,可以自己摸索。

 

这个不完美方法,MPDF只能解析相对简单的css(不能解析js和css中ul li等标签)。现在既然使用了wkhtmltoimage扩展,也就不在乎wkhtmltopdf的使用了。
同样,wkhtmltoimage 0.11会出现错误,需要下载0.10.0_rc2版。

32位:

代码如下:
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
tar jxf wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
cp wkhtmltoimage-i386 /usr/local/bin/wkhtmltopdf


 
64位

 

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2
mv wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2 wkhtmltoimage-0.10.0_rc2-static-amd64.tar
tar -xvf wkhtmltopdf-0.10.0_rc2-static-amd64.tar
mv wkhtmltoimage-amd64 /usr/bin/wkhtmltopdf测试 wkhtmltopdf http://www.你的域名.com/ 你的域名.pdfphp shell_exec() 执行shell_exec('/usr/local/bin/wkhtmltopdf http://www.你的域名.com/ /usr/local/wwwroot/你的域名.com/你的域名.pdf');

 


标签: PHP 实现 HTML 生成 PDF 文件 方法


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持