简体   繁体   English

在Codeigniter中生成html页面,使用Wkhtmltopdf打印

[英]Generate html page in Codeigniter, print with Wkhtmltopdf

I want to create a temporary html page or view dynamically to use Wkhtmltopdf and export it as a PDF document from that file. 我想创建一个临时html页面或动态查看以使用Wkhtmltopdf并将其从该文件导出为PDF文档。 It is a Codeigniter project (with which I'm not that familiar..) so firstly I am wondering if it is possible? 这是一个Codeigniter项目(我对此并不熟悉。)所以首先我想知道是否有可能?

My approach is simply: 我的方法很简单:

$pdf = new Pdf();
$pdf->addPage('http://pageToAdd.php');
$pdf->saveAs('/path/to/saveFolder/' . $filename);

Which is generating a pdf from the addPage, but I want that page to be created with dynamic contentent fetched from the database so I was thinking that I should load a view, save it temporary and then assign that file as pageToAdd.php. 这是从addPage生成pdf的,但是我希望使用从数据库中获取的动态内容来创建该页面,因此我认为我应该加载视图,将其临时保存,然后将该文件分配为pageToAdd.php。 Is this is possible and if so, how and where should I start? 这有可能吗?如果可以,我应该如何开始?

You can render a template into a variable: 您可以将模板渲染为变量:

$string = $this->load->view('myfile', ['foo' => 'bar'], true);

And also you can save it temporary if you need for creating pdf. 如果需要创建pdf,也可以将其临时保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM