将列表视图数据导出为 PDF


Export List View Data to Pdf

我正在使用Clist View在Facebook上显示数据,例如列表顶部帖子。现在有一个 下载选项 .我想下载 pdf 格式的 Clist 视图数据。我在谷歌上搜索,但我没有找到最好的例子。我应该怎么做才能下载pdf格式的clist视图数据。

列表视图小部件:

$this->widget('zii.widgets.CListView', array(
                            'dataProvider' => $data_top_posts,
                            'id' => 'tbl-top-posts',
                            'itemView' => '_top_posts',
                            'template' => '{items}',
                            'beforeAjaxUpdate' => 'js:function(id, data){
                                    $("#" + id + " .items span.empty").html("Loading... Please wait.");
                                }',
                            'afterAjaxUpdate' => 'js:function(){
                                      setProgressBar("#tbl-top-posts");
                                      }',
                            'viewData' => array(
                                'id' => 'tbl-top-posts',),
                        ));

这样的事情没有内置函数。但你可以做到:

  1. 使用 HTML 模板打印出您的视图,然后将该内容传递给 TCPDF

$pdf->AddPage();
$html = $this->renderPartial('view', ['params'], true);
// output the HTML content
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('example_021.pdf', 'I');
  1. 从当前视图制作图像并将该图像传递给 TCPDF。

html2canvas(document.getElementById('area')).then(function(canvas) {
    var data = canvas.toDataURL();
    $.ajax({
        url: 'savePDF.php',
        type: 'post',
        data: {imageSrc: data}
    });
});

您可以使用任何其他HTML到PDF工具,而不仅仅是TCPDF。


资源:
TCPDF, DomPDF
Html2Canvas