Динамические страницы с использованием FPDF

У меня есть ссылка на странице, которая генерирует PDF. Я использую fpdf для того же. Мое требование состоит в том, что мы должны создать один PDF-файл с разными страницами, каждая из которых имеет нижний колонтитул и верхний колонтитул.

Например. студент производит оплату наличными, чеками. Мне нужно создать PDF-файл, отображающий режим оплаты, сумму и т. д. Я запускаю цикл для каждого типа инструмента, но проблема в том, что PDF-файл показывает одну запись только потому, что я думаю, что она перезаписывается. Я пробовал разрыв страницы, но с успехом.

Код

require_once(APP_PHYSICAL_PATH."libs/fpdf/fpdf.php");

class PDF extends FPDF
{
    function Header()
    {
        $this->Image(APP_WEBROOT_PHYSICAL_PATH.'app_images/site-logo.gif',10,8,33);
        $this->Ln(15);

        $this->SetFont('Arial','B',12);
        $this->MultiCell(0,0,'mysite.',0,'C');
        $this->Ln(5);

        $this->SetFont('Arial','',10);
        $this->MultiCell(0,0,'67, addd2',0,'C');
        $this->Ln(5);

        $this->MultiCell(0,0,'Tel No - 010000000, Website:www.site.com',0,'C');
        $this->Ln(10);
    }

    function Footer()
    {
        $this->Ln(10);
        $this->SetFont('Arial','B',10);
        $this->MultiCell(0,0,'For mycomany.',0,'R');
        $this->Ln(20);
        $this->MultiCell(0,0,'Center Manager',0,'R');
    }

}
for($i=0;$i<3;$i++)
{ 
$pdf = new PDF();

$pdf->AddPage('P','Letter');
$pdf->SetAuthor("MYCompany");
$pdf->SetCreator("MYCompany");
$pdf->SetFont('Arial', 'B', 12);
$pdf->MultiCell(0, 0, 'Acknowledgement', 0, 'C');
$pdf->Ln(10);

$pdf->SetFont('Arial', 'B', 10);
$pdf->MultiCell(0,0,"Date: ".$details[0]['datepaid'],0,'L');
$pdf->MultiCell(0,0, "Acknowledgement No : ".date('Y/m/d')."/".$details[0]['pk_paymentid'],0,'R');
$pdf->Ln(10);

$pdf->SetFont('Arial','',10);
$pdf->MultiCell(0, 0, "We acknowledge receipt of Rs ".$details[0]['amountpaid']." from Ms/Mr ".$details[0]['fullname'], 0, 'J');
$pdf->Ln(5);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Course Name',1,0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,$details[0]['name'],1,0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Course Fee (Total)','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,round($courseData[0]['courseFee']),'LBR',0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,"Service Tax",'LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,round($courseData[0]['serviceTax']),'LBR',0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Total Amount Payable','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,round($courseData[0]['totalAmount']),'LBR',0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Amount Received','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,round($details[0]['amountpaid']),'LBR',0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Balance Amount Payable','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$balance=round($courseData[0]['totalAmount']-$details[0]['amountpaid']);
if($balance<1)
{
$balance=0;
}
 $pdf->Cell(90,7,$balance,'LBR',0,'L');
// $pdf->Cell(90,7,$courseData[0]['totalAmount']-$details[0]['amountpaid'],'LBR',0,'L');
 $pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Mode of Payment','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,"",'LBR',0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Cheque/Demand Draft/Credit Card Number','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,"",'LBR',0,'L');
$pdf->Ln(7);

$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,'Name of Bank and Branch','LBR',0,'L');
$pdf->SetFont('Arial','',10);
$pdf->Cell(90,7,"",'LBR',0,'L');
$pdf->Ln(20);

$pdf->SetFont('Arial','I',10);
$pdf->MultiCell(0,0,'* Service Tax Regn No _____________',0,'L');
$pdf->Ln(10);

$pdf->SetFont('Arial','',10);
$pdf->MultiCell(0, 0, 'For further processing of your registeration to the above program, we are forwarding your details to our enrollment center at', 0, 'L');
$pdf->Ln(5);
$pdf->MultiCell(0, 0, 'Centre. For all queries please contact:', 0, 'L');
$pdf->Ln(10);
$pdf->MultiCell(0,0,'myaddress',0,'L');
}
//$pdf->Output();
$pdf->Output('Enrolment_No_'.$details[0]['enrolmentid'].".pdf",'D');

Пожалуйста помоги мне с этим.

Спасибо


person Pankaj Khurana    schedule 20.05.2010    source источник
comment
Так в чем именно ваша проблема? Вы говорите о цикле, но в вашем коде цикла нет, поэтому мне кажется вполне нормальным, что вы получаете только одну запись.   -  person wimvds    schedule 20.05.2010
comment
@wimvds я удалил петлю, о которой упоминал в вопросе.   -  person Pankaj Khurana    schedule 20.05.2010
comment
Итак, как вы ожидаете, что мы найдем вашу ошибку, если вы удалили соответствующий код?   -  person wimvds    schedule 20.05.2010
comment
@wimvds я отредактировал вопрос и добавил цикл   -  person Pankaj Khurana    schedule 20.05.2010


Ответы (2)


Итак, теперь ваша ошибка совершенно очевидна. Вы должны поставить $pdf = new PDF(); перед циклом.

ie.

$pdf = new PDF();
for($i=0;$i<3;$i++)
{ 
    $pdf->AddPage('P','Letter');
    ...
person wimvds    schedule 20.05.2010

Я внимательно посмотрел на fpdi и tcpdf. Лучший способ прочитать расширенный PDF-файл таков:

class PDF extends FPDI { 
    var $_tplIdx;
    function Header() {}    
    function Footer() {}        
}

$pdf = new PDF();
$tpages = $pdf->setSourceFile("yourpdf.pdf");
/**
* Set a source-file
*
* @param string $filename a valid filename
* @return int number of available pages
*/

,... затем просто зациклите страницы, и все готово :)

person NetworkSys Co. Ltd    schedule 22.01.2013
comment
Чтобы запустить мой пример, вам нужно: fpdi: ссылка И: tcpdf с tpl: ссылка - person NetworkSys Co. Ltd; 23.01.2013