【问题标题】:tcpdf in codeigniter not workingcodeigniter中的tcpdf不工作
【发布时间】:2017-12-06 07:40:34
【问题描述】:

我使用 tcpdf 将数据生成为 pdf,但没有结果,也没有错误。

JS

obj.fnExportpdf = () => {
    return app.callModel('romans/pdfTest'
    // onerror
    , function (jqXHR, status, errorMessage){
            alert ('ERROR: '+errorMessage);
            return false;
    }
    // onsuccess
    , function (response, status, jqXHR){
            return ;
    }
    // hide progressbar
    , false
    );  
}

型号

 function pdfTest(){
    $this->load->library("Pdf");
    $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    // Add a page
    $pdf->AddPage();
    $html = "<h1>Test Page</h1>";
    $pdf->writeHTML($html, true, false, true, false, '');
    ob_clean();
    return $pdf->Output('samplepdf.pdf','I');

}

但是当我单击 pdftest 时,它会显示结果。 click image

【问题讨论】:

  • 你是如何配置Pdf库的?
  • 直接从浏览器调用时是否正常工作? , 表示localhost/yourapp/romans/pdfTest
  • 不在那个路径中。,我什至好奇为什么我可以在这个路径中调用它而不是 romans/index.php/report/pdfTest
  • 直接执行(不使用JS)得到PDF了吗?

标签: javascript php sql-server codeigniter tcpdf


【解决方案1】:

here下载 TCPD

创建一个新文件:/application/libraries/Pdf.php:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once dirname(__FILE__) . '/tcpdf/tcpdf.php';

class Pdf extends TCPDF
{
    function __construct()
    {
        parent::__construct();
    }
}

/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */

要创建新的 PDF,您可以在控制器中执行以下操作:

$this->load->library('Pdf');

$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('My Title');
$pdf->SetHeaderMargin(30);
$pdf->SetTopMargin(20);
$pdf->setFooterMargin(20);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('Author');
$pdf->SetDisplayMode('real', 'default');

$pdf->AddPage();

$pdf->Write(5, 'Some sample text');
$pdf->Output('My-File-Name.pdf', 'I');

【讨论】:

  • 还是一样。我试图在未定义的 JS 上提醒 response[error_message]。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-26
  • 2014-04-15
  • 2012-12-02
  • 1970-01-01
  • 2018-06-16
  • 2016-03-01
相关资源
最近更新 更多