doushou7169 2016-02-19 04:22
浏览 53
已采纳

将列表视图数据导出到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',),
                        ));
  • 写回答

1条回答 默认 最新

  • dttphb59319 2016-02-19 06:37
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?