dompdf 在 codeigniter 中生成损坏的 pdf
dompdf generating damaged pdfs in codeigniter
我正在使用 dompdf 在 codeigniter 应用程序中生成 pdf,
当我打开 pdf 时出现错误
我为此检查了所有 Whosebug 的资料,
- Corrupt PDF on the fly attached to email via dompdf
- cannot open pdf file generated using dompdf
- Generating a PDF using CodeIgniter
还有更多,但没有运气,
我的代码是:
$html = file_get_contents(base_url() . "sampleHTMLfilepath");
require_once("dompdf/dompdf_config.inc.php");
if (is_null($this->_dompdf)) {
$this->_dompdf = new DOMPDF();
}
$this->_dompdf->load_html($html);
$this->_dompdf->render();
$this->_dompdf->stream('test.pdf);
样本html是带有p标签的简单文件
<p>Hello </p>
请帮帮我,
谢谢
没有人应该对这个问题投反对票。无论如何在你的控制器方法中尝试这样的事情,转换为你使用。
// get some content
$data['order'] = $this->printmodel->getOrder();
// Load a view like you would normally do
$this->load->view('orderprint', $data);
// before going any further,
// make sure the content is showing on the view with no errors
// when you call the method
// all good? ok now add this part
// Get the output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Create pdf name based on date, hour, seconds
$pdfname = date("FjYgias");
// Convert to PDF
// (this is for streaming the pdf directly)
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream($pdfname);
这是一个比您尝试做的要复杂得多的示例 - 您不必调用模型等 - 您只需调用视图,
$this->load->view('somethingcooltoprint');
确认它的工作,然后像上面那样做剩下的代码。
我正在使用 dompdf 在 codeigniter 应用程序中生成 pdf, 当我打开 pdf 时出现错误
我为此检查了所有 Whosebug 的资料,
- Corrupt PDF on the fly attached to email via dompdf
- cannot open pdf file generated using dompdf
- Generating a PDF using CodeIgniter
还有更多,但没有运气, 我的代码是:
$html = file_get_contents(base_url() . "sampleHTMLfilepath");
require_once("dompdf/dompdf_config.inc.php");
if (is_null($this->_dompdf)) {
$this->_dompdf = new DOMPDF();
}
$this->_dompdf->load_html($html);
$this->_dompdf->render();
$this->_dompdf->stream('test.pdf);
样本html是带有p标签的简单文件
<p>Hello </p>
请帮帮我, 谢谢
没有人应该对这个问题投反对票。无论如何在你的控制器方法中尝试这样的事情,转换为你使用。
// get some content
$data['order'] = $this->printmodel->getOrder();
// Load a view like you would normally do
$this->load->view('orderprint', $data);
// before going any further,
// make sure the content is showing on the view with no errors
// when you call the method
// all good? ok now add this part
// Get the output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Create pdf name based on date, hour, seconds
$pdfname = date("FjYgias");
// Convert to PDF
// (this is for streaming the pdf directly)
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream($pdfname);
这是一个比您尝试做的要复杂得多的示例 - 您不必调用模型等 - 您只需调用视图,
$this->load->view('somethingcooltoprint');
确认它的工作,然后像上面那样做剩下的代码。