我已经开始尝试使用codeigniter和pdfs。我正在使用两者的最新版本。出于某种原因,我在尝试渲染 pdf 时收到此错误:
Warning: require_once(C:'Users'Manfred'Dropbox'Web'Alodu'application'helpers'dompdf/include/ci_exceptions.cls.php) [function.require-once]: failed to open stream: No such file or directory in C:'Users'Manfred'Dropbox'Web'Alodu'application'helpers'dompdf'dompdf_config.inc.php on line 208
Fatal error: require_once() [function.require]: Failed opening required 'C:'Users'Manfred'Dropbox'Web'Alodu'application'helpers'dompdf/include/ci_exceptions.cls.php' (include_path='.;C:'php'pear') in C:'Users'Manfred'Dropbox'Web'Alodu'application'helpers'dompdf'dompdf_config.inc.php on line 208
使用的代码是:
function pdf()
{
$this->load->helper(array('dompdf', 'file'));
// page info here, db calls, etc.
/*
$data=array(
"$title"=>"Hello!",
"$test_questions"=>"1,2,3,4",
);
*/
$data['test_questions']= "hello";
$html = $this->load->view('pdf/test_ibdp', $data, true);
$filename="Test".$data['test_questions'];
pdf_create($html, $filename);
write_file('name', $data);
}
而帮手:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait" );
$dompdf->render();
$dompdf->stream($filename . ".pdf");
}
?>
和视图(纯 HTML)
<html>
<head>
<title>Hello!</title>
</head>
<body>
<h1>HelloAgain</h1>
</body>
</html>
有什么建议吗?我在PHP方面没有经验,我很困惑。我刚刚重新下载了库,我试图通过去除代码中的附加内容来保持它非常简单。似乎什么都不起作用。任何帮助都会很棒:)
这是一个类自动加载器问题。您使用哪个版本的 DOMPDF?我认为dompdf 0.5在集成到像CI这样的框架中时遇到了问题。0.6 版本不再有这个问题了,如果问题仍然存在,写
define("DOMPDF_AUTOLOAD_PREPEND", true)
在dompdf_config.custom.inc.php
.
错误是说下面的路径不正确。重新检查路径
require_once("dompdf/dompdf_config.inc.php");
文件的路径不正确。
C:''Users''Manfred''Dropbox''Web''Alodu''application''helpers''dompdf /
包含 /
ci_exceptions.cls.php
您可以使用 DIRECTORY_SEPARATOR
.
更正 dompdf 文件路径。同时删除以下代码行:
write_file('name', $data);
以下行就足够了:
pdf_create($html, $filename);