【发布时间】:2016-05-09 09:54:31
【问题描述】:
您好,我是 yii 新手,所以目前不知道如何在 yii 中正确使用这个 Html2pdf 和 yii-pdf 扩展来获取 pdf..
我真正想要的.. 我有一个名为http://localhost/site/Users/Results.. 的页面显示用户列表..所以如果我点击用户一,它将打开一个名为http://localhost/site/Applicant/1 的新页面
& 对于用户二,它将是
http://localhost/site/Applicant/2
所以在这些页面上有用户的所有信息。我想在这个页面上放一个下载 PDF 按钮,如果用户点击它,他将能够以 PDF 格式下载他的所有信息。可以有很多用户。每个用户都可以以 pdf 格式下载他的所有信息。
我得到了html2pdf 和yii-PDF ..我通过在谷歌上搜索得到了这个设置,但找不到合适的例子来根据我上面的要求使用它。
配置/main.php
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'HTML2PDF' => array(
'librarySourcePath' => 'application.extensions.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
/*'defaultParams' => array( // More info: http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:accueil
'orientation' => 'P', // landscape or portrait orientation
'format' => 'A4', // format A4, A5, ...
'language' => 'en', // language: fr, en, it ...
'unicode' => true, // TRUE means clustering the input text IS unicode (default = true)
'encoding' => 'UTF-8', // charset encoding; Default is UTF-8
'marges' => array(5, 5, 5, 8), // margins by default, in order (left, top, right, bottom)
)*/
)
),
),
这是我的控制器。
class UsersController extends Controller
{
public function createPDF(){
$html2pdf = Yii::app()->ePdf->HTML2PDF();
$html2pdf->WriteHTML($this->renderPartial('index', array(), true));
$html2pdf->Output();
}
}
我对yii完全陌生,所以如何使用这个扩展,我以前从未使用过任何扩展..有没有其他方法可以下载每个用户信息的pdf。任何建议或工作代码示例。
【问题讨论】: