0

我正在使用 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',),
                        ));
4

1 回答 1

1

这种东西没有内置功能。但是你可以这样做:

  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。


资源:
TCPDFDomPDF
Html2Canvas

于 2016-02-19T06:37:23.550 回答