简体   繁体   中英

Codeigniter TCPDF - Load Multiple PDF

Current Issue:

When i click on "Print PDF" it only show "1" PDF.

What I Have Done:

I have set array on the URI , which means that it able to loop 2 times using foreach , but problem now is that the PDF is currently showing "1" time only

What I Need :

Allow TCPDF generate 2 pdf


Create this thread is whated to know the idea, i will try to solve it myself

Code

<?php
foreach($invoice as $row){  

$body='HTML 
XXXXXXX
Table';




$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Invoice');
$pdf->SetHeaderMargin(10);
$pdf->SetTopMargin(10);
$pdf->setFooterMargin(10);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('Invoice');
$pdf->SetDisplayMode('real', 'default');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

$pdf->AddPage();

$pdf->writeHTML($body, true, false, true, false, '');


$pdf->lastPage();

//$pdf->Write(5, $tnc);
$pdf->Output('InvoceOutput'.'\.pdf', 'I' );
}
?>

You're creating and outputting your PDF inside your for loop, so 2 separate PDFs that are 1 page long are being generated. The 2nd PDF is likely overwriting the 1st PDF, leaving you with a single PDF 1 page long.

Configuring and outputting your PDF outside of the for loop should fix your issue:

<?php
$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Invoice');
$pdf->SetHeaderMargin(10);
$pdf->SetTopMargin(10);
$pdf->setFooterMargin(10);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('Invoice');
$pdf->SetDisplayMode('real', 'default');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

foreach($invoice as $row){
    $body='HTML 
    XXXXXXX
    Table';

    $pdf->AddPage();
    $pdf->writeHTML($body, true, false, true, false, '');
    $pdf->lastPage();

    //$pdf->Write(5, $tnc);
}

$pdf->Output('InvoceOutput'.'\.pdf', 'I' );
?>

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