我需要以PDF格式创建我的所有学生结果,所以我使用TCPDF创建PDF。这是我的代码
$zip = new ZipArchive();
$filename = "/tmp/reports.zip";
$zip->open($filename, ZipArchive::CREATE);
foreach ($users_list as $i => $value) {
$obj_pdf = new TCPDF('P', 'pt', 'PDF_PAGE_FORMAT' , true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetPrintHeader( false );
$obj_pdf->SetPrintFooter( false );
$obj_pdf->AddPage('P' , 'A4');
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetTopMargin($margin_top . 'px');
$obj_pdf->SetLeftMargin (62);
$obj_pdf->SetRightMargin(50);
$obj_pdf->SetFontSize('22px', true);
$content = "<span style='letter-specing: 3px; font-weight: 700; line-height: 1.3;'>The Report</span>";
$obj_pdf->writeHTML($content, true, false , true, false, "L");
$obj_pdf->lastPage();
$obj_pdf->Output('/tmp/report_' . $i . '.pdf', 'F');
$obj_pdf->Close();
$zip->addFile('/tmp/report_' . $i . '.pdf','report_' . $user->display_name . '.pdf');
}
$zip->close();
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="certificates.zip"');
readfile($filename);
代码工作正常,它为每个用户创建一个单独的pdf用户名,但在pdf中我只获得最后的用户数据。我不知道为什么它表现得那样!我怎么解决这个问题 ?