【问题标题】:outputting smarty display function return to pdf using tcpdf使用 tcpdf 输出 smarty 显示功能返回 pdf
【发布时间】:2013-05-13 10:27:21
【问题描述】:

您好,我正在使用 smarty 打印日历.. 此日历使用行显示

$html= $obj_smarty->fetch(FULLCAL_DIR.'/views/cal.html');

在 php 中回显 $html 为我提供了正确的日历。但我想使用 tcpdf 将此输出打印到 pdf

我使用了以下几行:

$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('cal.pdf', 'I');

但它没有给我输出.. pdf 中只显示静态数据。请帮忙

更新 我的pdf生成代码如下: $this->load->library('tcpdf');

     $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
    //$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetTitle('Annual Planner');
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,"Annual Planner","", array(0,64,255), array(0,64,128));
    //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
    $pdf->setFooterData(array(0,64,0), array(0,64,128));

    // set header and footer fonts
    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    $pdf->setFontSubsetting(true);
    $pdf->SetFont('dejavusans', '', 14, '', true);
    $pdf->AddPage();
    $html = "";
    require_once (APPPATH.'calendar/cal_include/default.inc.php');

    $html.= $obj_smarty->fetch(FULLCAL_DIR.'/views/cal.html');
    // Print text using writeHTMLCell()
    $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

    $pdf->Output('cal.pdf', 'I');

【问题讨论】:

    标签: php smarty tcpdf


    【解决方案1】:

    我不确定您所说的“静态数据”是什么意思。 我们还使用 Smarty 构建具有动态内容的模板,然后将其推送到 writeHTML 函数:

    //CONTENT           
    $sContent = $this->_oPDF->parseTemplate ($sTemplate,$aData);
    
    //WRITE
    $this->_oPDF->writeHTML($sContent, true, false, false, false, '');
    

    parseTemplate()-method中的主要过程是(除了分配语言,清除编译的tpl等):

    //assigning dynamic data
    $oTemplate->assign($aData);
    //fetch template
    $sContent = $oTemplate->fetch($sTemplate);
    //return
    return $sContent;
    

    希望这会有所帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-28
      • 2016-04-19
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 2018-07-20
      • 2015-09-10
      相关资源
      最近更新 更多