简体   繁体   中英

Export List View Data to Pdf

I am using Clist View to show data such list top post on facebook. Now there is a download option . I want to download Clist view data in pdf format . I search on google but i don't find and best example. What should i do to download data of clist view in pdf format.

List view widget:

$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',),
                        ));

There is no build-in function for such thing. But you can make that:

  1. Use HTML template to print out your view and than pass that content to TCPDF

Example

$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. Make image from current view and pass that image to TCPDF.

Example

html2canvas(document.getElementById('area')).then(function(canvas) {
    var data = canvas.toDataURL();

    $.ajax({
        url: 'savePDF.php',
        type: 'post',
        data: {imageSrc: data}
    });
});

You can use any other HTML to PDF tool, not only TCPDF.


Resources:
TCPDF , DomPDF
Html2Canvas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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