【发布时间】:2014-05-26 07:43:07
【问题描述】:
我无法让 domPDF 工作。
我已经按照这篇文章完成了:https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf - 有一个例外:我从 Google (https://code.google.com/p/dompdf/downloads/detail?name=dompdf_0-6-0_beta3.zip&can=2&q=) 加载了它,因为 GitHub 中缺少文件(出于某种原因)
我尝试在 system/helpers 和 application/helpers 中都添加助手 - 但仍然遇到同样的问题。
我的控制器中有这个:
$this->load->helper(array('dompdf', 'file'));
//I know this is correct because $html returns content of view
$html = $this->load->view('actual viewfile', $content_data, TRUE);
//Try to create a pdf
pdf_create($html, '/pdf/test'); //It seems it's trying to create a pdf
//But...
echo 'FINAL'; //...it never reaches this line
exit;
我在 www 中创建了一个名为 pdf 的文件夹 - 根目录(不是应用程序根目录)
我不知道这有什么不同,但这就是我的 htaccess 的样子:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我也试过改成
define("DOMPDF_AUTOLOAD_PREPEND", true) in dompdf_config.custom.inc.php.
它似乎正在尝试创建 PDF,但似乎没有创建任何内容(并且它永远不会到达回显 final 的行。可能出了什么问题?
更新 经过一番搜索,我在我的 apache 错误日志中得到了这个:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 79 bytes) in C:\Program Files\wamp\www\mellomgarden2\application\helpers\dompdf\include\style.cls.php on line 718
【问题讨论】:
-
PHP 可以使用大约 128MB 内存。可能是 dompdf 和 CI 之间没有足够的可用内存。这是您可能必须在 php.ini 中设置的内容(取决于您的托管情况)。 dompdf 的内存需求很大程度上取决于 PDF 的内容和结构。查看示例文档可能有助于确定您遇到问题的原因。
-
请注意dompdf 0.6.0 final is available,因此您可能需要升级。如果您使用的是 PHP 5.4 或更高版本,您还可以考虑使用 dev branch,其中包括对内存使用的一些改进。
标签: .htaccess codeigniter helper dompdf