我需要创建正在更新的PDF文件。数据不时更新,每个新数据都放在新的文档行上。问题是,当文档的第一页填写时,我的程序将不会创建第二页。
这是我正在使用的代码
$newRecord="Sample Data";
$sourceFileName="pdf.pdf";
$pdf = new FPDI();
$pdf->SetAutoPageBreak(true, 0);
$pdf->AliasNbPages();
$pagecount = $pdf->setSourceFile($sourceFileName);
//echo $pagecount;
for ($loop = 1; $loop <= $pagecount; $loop++) {
$tplIdx = $pdf->importPage($loop);
$pdf->addPage();
$pdf->useTemplate($tplIdx, 0, 14);
}
$pdf->SetFont('Arial');
$pdf->SetTextColor(0,0,0);
$pdf->SetFontSize(14);
$pdf->Multicell(0,14,$newRecord);
$pdf->Output($sourceFileName, "F");
编辑1:这是我正在使用的整个脚本
<?php
$newRecord="Sample Data";
require_once('fpdf.php');
require_once('fpdi.php');
function createNewPDF($newRecord){//this function creates pdf it there is no pdf crated
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
$pdf->Multicell(0,14,$newRecord);
$pdfName=date('d-m-Y')."fitnessProgram.pdf";
$pdf->Output($pdfName,'F');
$today = date('Y-m-d');
$sql="INSERT INTO `pdf_files` (`id`, `date`, `expired`, `pdf_name`) VALUES (NULL, '$today', '0', '$pdfName')";
$sql_uname = mysql_query($sql) or die ('Unable to run query:'.mysql_error());
exit();
}
//function addNewRecord($newRecord){
include('db_connection.php');
$sql_uname = mysql_query("SELECT * FROM `pdf_files`") or die ('Unable to run query:'.mysql_error());;
if (!mysql_num_rows($sql_uname) > 0) {
createNewPDF($newRecord);
}
$sql_uname = mysql_query("SELECT `date`,`pdf_name` FROM `pdf_files` WHERE `expired`=0 LIMIT 1") or die ('Unable to run query:'.mysql_error());
if (mysql_num_rows($sql_uname) != 0) {
while($row = mysql_fetch_array($sql_uname)){
$date=$row["date"];
$sourceFileName=$row["pdf_name"];
}
}
if(strtotime($date)<strtotime('-30 days')){
$sql_uname = mysql_query("UPDATE `pdf_files` SET expired=1 WHERE expired=0");
createNewPDF($newRecord);
}
$newRecord="Sample Data";
$pdf = new FPDI();
$pdf->SetAutoPageBreak(true, 0);
$pdf->AliasNbPages();
$pagecount = $pdf->setSourceFile($sourceFileName);
echo $pagecount;
for ($loop = 1; $loop <= $pagecount; $loop++) {
$tplIdx = $pdf->importPage($loop);
$pdf->addPage();
$pdf->useTemplate($tplIdx, 0, 14);
$pdf->setPageMark();
}
$pdf->SetFont('Arial');
$pdf->SetTextColor(0,0,0);
$pdf->SetFontSize(14);
$pdf->Multicell(0,14,$newRecord);
$pdf->Output($sourceFileName, "F");
//}
?>