2016-08-24 8 views
5

私はcodeigniterでHTML2PDFライブラリを使用しています。私はそれを使用してバルクPDFを生成しようとしています。私はすべてのPDFまたはPDFファイルで同じ内容のような問題に直面していたではcodeigniterのhtml2pdfを使用したバルクpdf生成

にはcontent.Iはすでに私のhomework.Yeahをやっていないしているが、常に(アカウントの場合:3)生成された最初のPDFファイルのための完璧な存在見せている

ob_start(); 
    require_once($template_config.'template.php'); // 
    $content = ob_get_contents(); 
    ob_clean(); 

問題:私あたり以下のようにコードの問題でなければならないがありそれは最初の時間のために働くが、2番目の時間のためにそれはコンテンツ変数のすべてのコンテンツをフラッシュし、原因その重複したPDFにまたはコンテンツPDFを生成せずに。

私は

1以下のように試してみました

は)generatetemplate.phpでオブジェクトを作成し、

2をcommon.phpのために渡す)のinclude_onceは//すべてのPDFファイルに同じconentを取得し、私はエコーをやっている場合で試してみましたその後、第2、第3のpdf

File structure : 
    application 
     controllers 
      generatetemplate.php 
     libraries 
      common.php 
      html2pdf 
       html2pdf.php 
     template.php 


common.php : 

function print_content($customerdata){ 
    $this->load->library('/html2pdf/html2pdf'); 
    $template_config=$this->config->item('template'); 
    ob_start(); 
    require_once($template_config.'template.php'); // 
    $content = ob_get_contents(); 
    ob_clean(); 
    $content = str_replace("<CUSTOMER_ADDRESS>",$CUSTOMER_ADDRESS,$content); 
    $this->CI->html2pdf->pdf->SetDisplayMode('fullpage'); 
    $this->CI->html2pdf->writeHTML($content); 
    $this->CI->html2pdf->Output($download_path,"F"); 
} 

generatetemplate.php 
    function __construct() { 
     parent::__construct(); 
     $this->load->library("common"); 
     $this->load->library('html2pdf'); 
    } 
    function get_customer_data(){ 
     $this->db->order_by("id","DESC"); 
     $this->db->where('id IN (1,2,3)'); 
     $query = $this->db->get("customers")->result_array(); 
     foreach($query as $key=>$accountdata){ 
     $this->common->print_content($accountdata); 
     } 
    } 

のための内容すべてのヘルプやアイデアを示していないことは理解されるであろう。

+0

それは、多分、あなたは(すなわち 'generatetemplate.php'にし、common.php''で)二度 'html2pdf'ライブラリをロードしているようですか? – Tpojka

+0

hav見てhttp://stackoverflow.com/questions/32225465/multiple-pdf-files-with-html2pdf –

+0

@ safinchackoええ私はすでに1つを試みたが、動作していない –

答えて

0

私は以下のコードと私の仕事を試しました。

common.phpの

function print_content($customerdata){ 
    $this->load->library('/html2pdf/html2pdf'); 
    $template_config=$this->config->item('template'); 
    ob_start(); 
    require_once($template_config.'template.php'); // 
    $content = ob_get_contents(); 
    ob_clean(); 
    $content = str_replace("<CUSTOMER_ADDRESS>",$CUSTOMER_ADDRESS,$content); 
    $this->CI->html2pdf = new HTML2PDF('P','A4','en'); // Just added this line and its work for me. 
    $this->CI->html2pdf->pdf->SetDisplayMode('fullpage'); 
    $this->CI->html2pdf->writeHTML($content); 
    $this->CI->html2pdf->Output($download_path,"F"); 
} 
関連する問題