我正在使用tcpdf库来创建pdf。我想多次下载相同的pdf(用户将输入他想要的pdf数量)。我做了一个for循环,根据用户输入的值调用pdf函数。问题是在创建第一个pdf后代码停止。以下是我的pdf函数,我多次调用它。创建pdf大约需要10-15秒。谢谢!
public function generatePdf($eventId) {
$eventDetails = $this->events_model->getAttachment($eventId);
$image = $eventDetails[0]->image_source;
$startTime = $eventDetails[0]->startTime;
$regTime = $eventDetails[0]->regTime;
$locationName = $eventDetails[0]->location_name;
$location = $eventDetails[0]->location;
$date = strtotime($startTime);
$date1 = strtotime($regTime);
$dat = date('m/d/y', $date);
$tme = date('H:m', $date);
$regTme = date('m/d/ H:m', $date1);
$this->load->library('Pdf');
$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Event Ticket');
$pdf->SetTopMargin(0);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);
$pdf->setFooterMargin(0);
$pdf->setLeftMargin(0);
$pdf->setRightMargin(0);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('MPM');
$pdf->SetDisplayMode('real', 'default');
$pdf->AddPage();
$pdf->SetFont('Helvetica');
$pdf->SetFontSize('10');
$pdf->SetFont('', 'B');
$y = $pdf->getY();
$pdf->setCellPaddings(0, 1, 2, 1);
$pdf->SetFillColor(215, 235, 255);
$event_pic = './eventDocs/' . $image;
$logo_html = '<img width="196px;" height="700px;" src="' . base_url() . $event_pic . '" />';
$event_fixed_pic = './eventDocs/Untitled-2.png';
$event_fixed_pic_html = '<img height="200px;" src="' . base_url() . $event_fixed_pic . '" />';
$event_bottom_pic = './eventDocs/Untitled-4447.png';
$event_bottom_pic_html = '<img width="595px;" height="146px;" src="' . base_url() . $event_bottom_pic . '" />';
$pdf->writeHTMLCell(80, 280, '', $y, $logo_html, 0, 0, 0, false, '', true);
$pdf->setCellPaddings(60, 1, 2, 1);
$pdf->SetFont('', 'B', 14);
$pdf->SetTextColor(195, 195, 176);
$pdf->MultiCell(130, 5, $startTime, 0, false, 0, 0, '', '', true);
$pdf->Ln(25);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->SetFont('', 'B', 15);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(140, 5, utf8_to_german($this->lang->line("event_pdf_top_heading1")), 0, false, 0, 0, '', '', true);
$pdf->Ln(6);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->MultiCell(170, 5, utf8_to_german($this->lang->line("event_pdf_top_heading2")), 0, false, 0, 0, '', '', true);
$linestyle = array('width' => 1.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(195, 195, 176));
$pdf->Line(75, 40, 149, 40, $linestyle);
$pdf->SetLineStyle(array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Ln(18);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->SetFont('', 'B', 11);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(150, 5, utf8_to_german($this->lang->line("event_pdf_heading1")), 0, false, 0, 0, '', '', true);
$pdf->Ln(8);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->MultiCell(200, 5, utf8_to_german($this->lang->line("event_pdf_heading2")), 0, false, 0, 0, '', '', true);
$pdf->Ln(38);
$pdf->setCellPaddings(5, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->SetFillColor(199, 195, 176);
$pdf->writeHTMLCell(60, 43, 0, 95, $locationName . '<br>' . $location, 0, 0, 1, false, '', true);
$pdf->Ln(140);
$pdf->setCellMargins(140, 95);
$pdf->writeHTMLCell('', 30, '', $y, $event_fixed_pic_html, 0, 0, 0, false, '', true);
$pdf->Ln(60);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(100, 5, utf8_to_german($this->lang->line("event_pdf_heading3")), 0, false, 0, 0, '', '', true);
$linestyle = array('width' => 1.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(195, 195, 176));
$pdf->Line(75, 163, 146, 163, $linestyle);
$pdf->SetLineStyle(array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Ln(11);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->SetFont('', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(120, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para1")), 0, false, 0, 0, '', '', true);
$pdf->Ln(35);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(120, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para2")), 0, false, 0, 0, '', '', true);
$pdf->Ln(10);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(120, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para3")), 0, false, 0, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(100, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para4")), 0, false, 0, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellMargins(0, 240);
$pdf->writeHTMLCell(500, 52, '', $y, $event_bottom_pic_html, 0, 0, 1, false, '', true);
$pdf->SetFont('', '', 12);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 15, 2, 1);
$pdf->setCellMargins(10);
$pdf->MultiCell(50, 30, $locationName . ' ' . $location, 0, false, 1, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 10, 2, 1);
$pdf->setCellMargins(70);
$pdf->MultiCell(50, 10, $dat, 0, false, 1, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 13, 2, 1);
$pdf->setCellMargins(70);
$pdf->MultiCell(50, 10, utf8_to_german($this->lang->line("event_pdf_footer_para3")) . $regTme . $this->lang->line("event_pdf_footer_time"), 0, false, 1, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 18, 2, 1);
$pdf->setCellMargins(70);
$pdf->MultiCell(50, 10, utf8_to_german($this->lang->line("event_pdf_footer_para4")) . $tme . $this->lang->line("event_pdf_footer_time"), 0, false, 1, 0, '', '', true);
ob_end_clean();
$pdf->Output('pdfexample.pdf', 'D');
$pdf->Output('pdfexample1.pdf', 'D');
return 1;
}