[英]Problems using dompdf and codeigniter
I have started experimenting with codeigniter and pdfs. 我已经开始尝试使用Codeigniter和pdf。 I'm using the latest version of both. 我正在使用两者的最新版本。 For some reason, i'm getting this error when trying to render the 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
Code used is: 使用的代码是:
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);
}
And the helper: 和助手:
<?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");
}
?>
and the view (pure HTML) 和视图(纯HTML)
<html>
<head>
<title>Hello!</title>
</head>
<body>
<h1>HelloAgain</h1>
</body>
</html>
Any suggestions? 有什么建议么? I'm not that experienced in PHP and i'm quite confused. 我没有PHP的经验,我很困惑。 I just re-downloaded the library, i've tried keeping it really simple by stripping away extras in my code. 我只是重新下载了该库,我尝试通过剥离代码中的其他内容来使其保持非常简单。 Nothing seems to work. 似乎没有任何作用。 any help would be great :) 任何帮助将是巨大的:)
This is a class autoloader issue. 这是一类自动加载器问题。 Which version of DOMPDF do you use? 您使用哪个版本的DOMPDF? I think dompdf 0.5 had a problem when integrated inside a framework like CI. 我认为dompdf 0.5集成到类似CI的框架中时会出现问题。 The 0.6 version doesn't have this probleme anymore, and if the problem persists, write 0.6版本不再有此问题,如果问题仍然存在,请写
define("DOMPDF_AUTOLOAD_PREPEND", true)
in dompdf_config.custom.inc.php
. 在dompdf_config.custom.inc.php
。
Correct the dompdf file path. 更正dompdf文件路径。 Also remove this line of code: 还要删除以下代码行:
write_file('name', $data);
The following line is enough: 以下行就足够了:
pdf_create($html, $filename);
The error is saying the path below is not correct. 该错误表明下面的路径不正确。 Recheck the path 重新检查路径
require_once("dompdf/dompdf_config.inc.php");
Path to the file is incorrect. 文件路径不正确。
C:\\Users\\Manfred\\Dropbox\\Web\\Alodu\\application\\helpers\\dompdf /
include /
ci_exceptions.cls.php C:\\ Users \\ Manfred \\ Dropbox \\ Web \\ Alodu \\ application \\ helpers \\ dompdf /
include /
ci_exceptions.cls.php
You can use DIRECTORY_SEPARATOR
. 您可以使用DIRECTORY_SEPARATOR
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.