我在PHP程序中生成PDF文档,但是PDF文档每次都会出现一个背景文字,如:www.phplib.com这些字,如何把这些字去掉呢,下面的是原程序:
<?
try {
$p = new PDFlib(); if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->begin_page_ext(595, 842, ""); $font = $p->load_font("Helvetica-Bold", "winansi", "");
$p->setfont($font, 24.0);
$p->set_text_pos(50, 700);
$p->show_xy("Hello world (PHP)!",100 , 750 );
$p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer();
$len = strlen($buf); header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;}
catch (PDFlibException $e) {
die("PDFlib exception occurred in hello sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n");
}
catch (Exception $e) {
die($e);
}$p = 0;
?>谢谢!
<?
try {
$p = new PDFlib(); if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->begin_page_ext(595, 842, ""); $font = $p->load_font("Helvetica-Bold", "winansi", "");
$p->setfont($font, 24.0);
$p->set_text_pos(50, 700);
$p->show_xy("Hello world (PHP)!",100 , 750 );
$p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer();
$len = strlen($buf); header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;}
catch (PDFlibException $e) {
die("PDFlib exception occurred in hello sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n");
}
catch (Exception $e) {
die($e);
}$p = 0;
?>谢谢!
要么看看api是否允许把背景去掉,如果是强制加的背景,那就有点恶心了...
要么用其它开源的pdf类库,大把啊,比如我就用dompdf,还有fpdf..
dompdf:
http://www.digitaljunkies.ca/dompdf/examples.php
例子:
require_once("dompdf_config.inc.php");$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
dompdf强大之处在于,直接将不是很复杂的html转成pdf,支持外部样式(必须css2.0规范),支持table嵌套...所以一些简单的pdf页面,你就在php端输出个简单的html串,调用它的load_html方法,它会自动将html转成pdf格式.开源而且能做到这样的功能,dompdf已经足够强大了.fpdf也不错,http://www.fpdf.org
http://www.docin.com/p-25286971.html看看教程
在设置的第一行
error_reporting(0);改成error_reporting(E_ALL);看看错误信息。
Fatal error: Call to undefined function: sys_get_temp_dir() in E:\espow\ADMIN\sale\dompdf\dompdf_config.inc.php on line 125这个错误提示在我本地上也有过这个提示,我把它屏蔽了,也可以运行,但到了服务器就不行了。这个该怎么修改呢?
手册:
==========================
sys_get_temp_dir(PHP 5 >= 5.2.1)sys_get_temp_dir — Returns directory path used for temporary files
你php版本是5.2+么?不是的话用不了,你是不是下的最新版本?刚发现7月份又有新的版本出来,我没用过,我用的是dompdf-0.5.1.zip (432 KB, date: 2009-04-29)这个版本。你试试看。
我刚查了一下服务器上的是4.3的版本,可能用不了