簡體   English   中英

將列表視圖數據導出到Pdf

[英]Export List View Data to Pdf

我正在使用Clist View在Facebook上顯示此類列表頂部帖子的數據。 現在有一個下載選項。 我想下載pdf格式的Clist視圖數據。 我在Google上搜索,但找不到最佳例子。 我應該怎么做才能下載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。


資源:
TCPDFDOMPDF
Html2Canvas

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM