我把xml改成public 里 现在提示错误DOMDocument Object ( ) Warning: Cannot modify header information - headers already sent by (output started at G:\AppServ\www\6\1.php:16) in G:\AppServ\www\6\include\gd_adapter.cls.php on line 736Warning: Cannot modify header information - headers already sent by (output started at G:\AppServ\www\6\1.php:16) in G:\AppServ\www\6\include\gd_adapter.cls.php on line 751
不报错似乎不应该 gd写文字总是需要字体文件的 dompdf的默认字体是 Times-Roman 为此作为测试,你可以将任意一款ttf中文字体复制到 lib/fonts 目录中,并更名为 Times-Roman.ttf版本声明<?php /** * DOMPDF - PHP5 HTML to PDF renderer * * File: $RCSfile: dompdf.php,v $ * Created on: 2004-06-22 * * Copyright (c) 2004 - Benj Carson <[email protected]> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library in the file LICENSE.LGPL; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * * Alternatively, you may distribute this software under the terms of the * PHP License, version 3.0 or later. A copy of this license should have * been distributed with this file in the file LICENSE.PHP . If this is not * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. * * The latest version of DOMPDF might be available at: * http://www.digitaljunkies.ca/dompdf * * dompdf.php is a simple script to drive DOMPDF. It can be executed from * a browser or from the command line. * * @link http://www.digitaljunkies.ca/dompdf * @copyright 2004 Benj Carson * @author Benj Carson <[email protected]> * @package dompdf * @version 0.5.1 *//* $Id: dompdf.php,v 1.24 2009-04-29 04:11:35 benjcarson Exp $ */
1、使用 java 的 html2image
2、使用 TCPDF 生成 pdf 然后...
3、使用 php 的截屏函数 imagegrabscreen、imagegrabwindow
https://zh.wikipedia.org/wiki/Webkit
https://en.wikipedia.org/wiki/Webkit
先 define('DOMPDF_PDF_BACKEND', 'gd'); 就可生成图片
require_once("dompdf_config.inc.php");$html =<<< HTML
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<div>
<font color="red">文字信息</font>
<br>
<font>换行</font>
</div>
HTML;$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream('');
http://code.google.com/p/dompdf/downloads/list
它使用 DOMDocument 解析 html
print_r($dompdf->_xml);
可以看到解析是否正常
看到提示错误了
Fatal error: Cannot access protected property DOMPDF::$_xml in G:\AppServ\www\6\1.php on line 16
dompdf.cls.php 中有
class DOMPDF {
protected $_xml;但我在 php5.4.12 中依然可以看到
DOMPDF Object
(
[_xml:protected] => DOMDocument Object
(
[doctype] => (object value omitted)
....你可以将他改为 public 模式的
我的php版本是 PHP Version 5.2.6
我下载的dompdf是 @version $Id: dompdf.cls.php 468 2012-02-05 10:51:40Z fabien.menager 应该是最新的
Warning: Cannot modify header information - headers already sent by (output started at G:\AppServ\www\6\1.php:16) in G:\AppServ\www\6\include\gd_adapter.cls.php on line 736Warning: Cannot modify header information - headers already sent by (output started at G:\AppServ\www\6\1.php:16) in G:\AppServ\www\6\include\gd_adapter.cls.php on line 751
http://zh.wikipedia.org/wiki/Webkit
http://en.wikipedia.org/wiki/Webkit不过 PHP 好像也没webkithttp://www.phpclasses.org/package/7460-PHP-Convert-HTML-to-PDF-using-the-Webkit-engine.html
看看这个有没帮助
由于 dompdf 提供了生成图片的功能,所以也只是在正确生成 pdf 的基础上,通过定义 DOMPDF_PDF_BACKEND 常量将其图片生成的功能调出来而已
至于在测试时修改它的部分代码,这也是出于测试、分析的需要。也当然是自己对修改产生的后果负责
gd写文字总是需要字体文件的
dompdf的默认字体是 Times-Roman
为此作为测试,你可以将任意一款ttf中文字体复制到 lib/fonts 目录中,并更名为 Times-Roman.ttf版本声明<?php
/**
* DOMPDF - PHP5 HTML to PDF renderer
*
* File: $RCSfile: dompdf.php,v $
* Created on: 2004-06-22
*
* Copyright (c) 2004 - Benj Carson <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library in the file LICENSE.LGPL; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* Alternatively, you may distribute this software under the terms of the
* PHP License, version 3.0 or later. A copy of this license should have
* been distributed with this file in the file LICENSE.PHP . If this is not
* the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
*
* The latest version of DOMPDF might be available at:
* http://www.digitaljunkies.ca/dompdf
*
* dompdf.php is a simple script to drive DOMPDF. It can be executed from
* a browser or from the command line.
*
* @link http://www.digitaljunkies.ca/dompdf
* @copyright 2004 Benj Carson
* @author Benj Carson <[email protected]>
* @package dompdf
* @version 0.5.1
*//* $Id: dompdf.php,v 1.24 2009-04-29 04:11:35 benjcarson Exp $ */
可还是无法显示图片,还是打叉的,我也下的是你上面这个版本* @version 0.5.1了
*//* $Id: dompdf.php,v 1.17 2006/07/07 21:31:02 benjcarson Exp $ */是1.17的,不是1.24的,你能把你这个1.24的打包发出来测试下不?
所以被解析的 HTML 文档中一定要有语言声明
<meta http-equiv="Content-Type" content="text/html; charset=编码">
否则将按欧洲语言解析,汉字就不能显示了
@version $Id: dompdf.php 448 2011-11-13 13:00:03Z fabien.menager $补上字体文件 Times-Roman.ttf
#6 的代码即可正常运行
但比起 tcpdf 来就差的太远了,只是 tcpdf 尚不支持输出图片。改起来也太费劲了
imagepng($im, "myscreenshot.png");
imagedestroy($im);不过很慢,1440 x 900 大约 十七八秒由于 php5.4 不再支持 com 了,imagegrabwindow 未作测试真不如 [Prtsc Sys Rq] 和 [Alt]+[Prtsc Sys Rq] 在粘贴到“画图”中来的快
只要对 css 很熟悉的话,做起来并不复杂
用 DOMDocument::loadHTML 载入 html
析出各个元素的属性
计算每个盒子的尺寸和位置 这个比较复杂,需对 css 很熟悉
逐一绘制
反正那个我测试了不行
http://www.tqcp.net/kong_bct.php
你看他这个是如何做到的,他这个就是动态生成图片的哦,格式还很漂亮,究竟PHP怎么做到的?
$im = imagecreatefromstring(get());
$ind = vertical($im);//取得垂直分布,用人工分析比较简单
$w = imagesx($im);//抽取头部
$top_h = 59;
$top = imagecreate($w, $top_h);
imagecopy($top, $im, 0, 0, 0, 0, $w, $top_h);
for($y=6; $y<29; $y++) imagecopy($top, $top, 0, $y, 0, 5, $w, 1);
//imagegif($top); exit; //抽取中段(空白的)
$middle_h = 29;
$middle = imagecreate($w, $middle_h);
imagecopy($middle, $im, 0, 0, 0, 59, $w, $middle_h);
for($y=2; $y<$middle_h-1; $y++) imagecopy($middle, $middle, 0, $y, 0, 1, $w, 1);
//imagegif($middle); exit;//抽取中段(红色分隔线空白的)
$middlered_h = 29;
$middlered = imagecreate($w, $middlered_h);
imagecopy($middlered, $im, 0, 0, 0, 175, $w, $middle_h);
for($y=2; $y<$middle_h-1; $y++) imagecopy($middlered, $middlered, 0, $y, 0, 1, $w, 1);
//imagegif($middlered); exit;//抽取底部
$bottom_h = 41;
$bottom = imagecreate($w, $bottom_h);
imagecopy($bottom, $im, 0, 0, 0, 318, $w, $bottom_h);
//imagegif($bottom); /*
至此,我们已经准备好了组装空白彩票的部件。对于你自己的图片,当然是要自己动手画一些了
他的组装规则是:
头部 + ((行数 - 1) % 4) * 中段 + ceil((行数 - 1) / 4) * (红线中段 + 3 * 中段)+ 中段 + 底部(底部上压一线)现在就按次规则组装
*/
$row = 11;
$h = $top_h + (($row - 1) % 4) * $middle_h + ceil($row / 4) * 4 * $middle_h + $middle_h - 1 + $bottom_h;
$new = imagecreate($w, $h);
$y = 0;
$k = 0;
imagecopy($new, $top, 0, $y, 0, 0, $w, $top_h);
$y += $top_h;
for($i=0; $i<($row - 1) % 4; $i++, $y+=$middle_h) {
imagecopy($new, $middle, 0, $y, 0, 0, $w, $middle_h);
$k++;
}
for($i=0; $i<ceil($row / 4) * 4; $i++, $y+=$middle_h) {
if($k++ && $i % 4 == 0) imagecopy($new, $middlered, 0, $y, 0, 0, $w, $middle_h);
else imagecopy($new, $middle, 0, $y, 0, 0, $w, $middle_h);
}
imagecopy($new, $middle, 0, $y, 0, 0, $w, $middle_h);
$y += $middle_h;
imagecopy($new, $bottom, 0, $y-1, 0, 0, $w, $bottom_h);imagegif($new);function vertical($im) {
$num = 0;
for($y=0; $y<imagesy($im); $y++) {
$p = imagecolorat($im, 6, $y);
if($y == 0) $last = $p;
if($p != $last && $num) {
$res[$y-$num] = array($last, $num);
$last = $p;
$num = 0;
}
$num++;
}
$res[$y-$num] = array($last, $num);
//print_r($res);//$ind 保存了像素的垂直分布
return $res;
}function get($n=5) {
$url = 'http://www.tqcp.net/ct_end.php';
$param = array('nqis' => $n, 'cmdOk' => '确定');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
刚刚想明白他的,应该是实现有了一张空白图片,然后利用这个空白图片重新组合的,不过他这个也有点限制了
,假设,我要弄成一行并列4个像他这样的一张图片,貌似就不好做的了,难道要不断判断么?要选择哪个模板图片么?就想有没有方便点,直接利用html组合的
刚刚想明白他的,应该是实现有了一张空白图片,然后利用这个空白图片重新组合的,不过他这个也有点限制了
,假设,我要弄成一行并列4个像他这样的一张图片,貌似就不好做的了,难道要不断判断么?要选择哪个模板图片么?就想有没有方便点,直接利用html组合的
你如果做过图片联系表(photo contactsheet),就知道了
就是先定好行列数,每个thumb的尺寸,那么做底的图片尺寸也出来了
然后对每张图做thumb,贴到底图的相应坐标位置就完成了
你好,麻烦问下, 我转文字,加了样式都没有问题,但是当包含img标签的时候,即我想将图文混排的内容变成图片,这个时候,那个img标签就不显示图片了。 只显示一个默认的X图片 要如何解决呢