php - FPDF won't create new page -
i need create pdf file updating. data updated time time , every new data placed on new line of document. problem when first page of document filled, program won't create second page.
here code using
$newrecord="sample data"; $sourcefilename="pdf.pdf"; $pdf = new fpdi(); $pdf->setautopagebreak(true, 0); $pdf->aliasnbpages(); $pagecount = $pdf->setsourcefile($sourcefilename); //echo $pagecount; ($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");
edit 1: here whole script using
<?php $newrecord="sample data"; require_once('fpdf.php'); require_once('fpdi.php'); function createnewpdf($newrecord){//this function creates pdf there 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 `pdf_files` (`id`, `date`, `expired`, `pdf_name`) values (null, '$today', '0', '$pdfname')"; $sql_uname = mysql_query($sql) or die ('unable run query:'.mysql_error()); exit(); } //function addnewrecord($newrecord){ include('db_connection.php'); $sql_uname = mysql_query("select * `pdf_files`") or die ('unable run query:'.mysql_error());; if (!mysql_num_rows($sql_uname) > 0) { createnewpdf($newrecord); } $sql_uname = mysql_query("select `date`,`pdf_name` `pdf_files` `expired`=0 limit 1") or die ('unable 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 expired=0"); createnewpdf($newrecord); } $newrecord="sample data"; $pdf = new fpdi(); $pdf->setautopagebreak(true, 0); $pdf->aliasnbpages(); $pagecount = $pdf->setsourcefile($sourcefilename); echo $pagecount; ($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"); //} ?>
Comments
Post a Comment