Currently, I create a system that can generate PDF. Data at the PDF is from MySQL Database. For now, I display the data like this
First page: Only display one data.
Second page on words: will display data (maximum 3 data per page)
To be more clear, example I have 6 data, it will display like this:
First page = 1 data display
Second Page = 3 data display
Third page 2 data display
Now, I want to add the footer. The footer will display at the end of the page (at the bottom). I already created the footer.
If the LAST PAGE contain 1 or 2 data, the footer will display at the bottom of that page. BUT... if The LAST PAGE contain 3 data, the footer will display at bottom of next page (blank page). I dont know what is the problem. Can anyone help?
Below is my code
$user3 = $conn->query("SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id
WHERE ot_team.team_id = '".$_GET['team']."' AND report_date BETWEEN '".$_GET["from"]."' AND '".$_GET["to"]."' ORDER BY ot_report.report_date DESC");
$count = 0;
while ($row = $user3->fetch(PDO::FETCH_ASSOC)){
$pdf->SetFont('Arial','B',10);
$pdf->Cell(20,7,'Date:',1,0);
$pdf->Cell(67,7,date('d-m-Y',strtotime($row['report_date'])),1,0);
$pdf->Cell(20,7,'Time:',1,0);
$pdf->Cell(34,7,"From: ".date('H:i',strtotime($row['ot_start'])),1,0);
$pdf->Cell(33,7,"To: ".date('H:i',strtotime($row['ot_end'])),1,1);
$pdf->Cell(87,7,'Before',1,0,'C');
$pdf->Cell(87,7,'After',1,1, 'C');
$logo = file_get_contents('../../images/faces/noimage.png');
if(!isset($row['photo_before']) || empty($row['photo_before'])) {
$pdf->Cell(87, 57, $pdf->MemImage($logo, $pdf->GetX()+20, $pdf->GetY()+5, 47,47,), 1, 0, 'C');
}else{
$pdf->Cell(87, 57, $pdf->MemImage(base64_decode($row['photo_before']), $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 0, 'C');
}
if(!isset($row['photo_after']) || empty($row['photo_after'])) {
$pdf->Cell(87, 57, $pdf->MemImage($logo, $pdf->GetX()+20, $pdf->GetY()+5, 47,47,), 1, 1, 'C');
}else{
$pdf->Cell(87, 57, $pdf->MemImage(base64_decode($row['photo_after']), $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 1, 'C');
}
if ($row['time_photo_before'] == null){
$pdf->Cell(87,7,'-',1,0, 'C');
}else{
$pdf->Cell(87,7,$row['time_photo_before'],1,0, 'C');
}
if ($row['time_photo_after'] == null){
$pdf->Cell(87,7,'-',1,1, 'C');
}else{
$pdf->Cell(87,7,$row['time_photo_after'],1,1, 'C');
}
if ((($count - 3) % 3) === 0) {
$pdf->AddPage();
$pdf->Cell(60,7,'',0,1,"C");
}
$count++;
}
$pdf->Footer($pdf->SetY(-48));
$pdf->Footer($pdf->SetFont('Arial','B',9));
$pdf->Footer($pdf->Cell(58,9,'Prepared by,',0,0,"C"));
$pdf->Footer($pdf->Cell(58,9,'Verified by,',0,0,"C"));
$pdf->Footer($pdf->Cell(58,9,'Approved by,',0,1,"C"));
$pdf->Output();
?>
Extend the FPDF class and modify the default footer. Any time a new page is started the contents of the footer method will be called which should get you the desired result.
class PDF extends FPDF {
function Footer() {
$this->SetY(-48));
$this->SetFont('Arial','B',9));
$this->Cell(58,9,'Prepared by,',0,0,"C"));
$this->Cell(58,9,'Verified by,',0,0,"C"));
$this->Cell(58,9,'Approved by,',0,1,"C"));
} // end of the Footer function
} // end of the PDF class
I have dynamic data. So my data can change
besides that I also have a data signature that cannot be separated.
This signature data must be on the same page. See the red mark in this image :
It is a unit and cannot be separated. Signature data
must be on the same page
My problem is because my data is dynamic. This makes the position of the signature data can be located in any position. See image below :
Because my data increases, the position of the headmaster in the signature data is separate
How do I make signature data (see picture 1), which red marks automatically move to the next page if the data is separate?
You can set manual page breaks with something like this:
<?php
//All lines are written from the sheet code at this moment
//The code will insert a page break and the repeated header
//Page margins
$sheet->getPageMargins()->setTop(0.5);
$sheet->getPageMargins()->setRight(0.75);
$sheet->getPageMargins()->setLeft(0.75);
$sheet->getPageMargins()->setBottom(1);
//Use fit to page for the horizontal direction
$sheet->getPageSetup()->setFitToWidth(1);
$sheet->getPageSetup()->setFitToHeight(0);
$headerItems = array(); //add your header items here as array
$headerRowsHeight = 0;// calculated height of header and images of the top
$rowCounter = 100; //get last written row
//add (other) modifier of page hight here
$pageHeight=25+50 + $headerRowsHeight; //Current used page height Header + Footer + $headerRowsHeight
$reset = $pageHeight; //If you will have the firstpage diffrent change reset value and/or pageheight
$pageMaxHeight = 980 ; //Maximale page height DIN A4 arround this
$pageClearance = 15; //Clearance of footer
//Iterate trough all written lines
for ($row = 1; $row <= $rowCounter; ++$row) {
$height=15.1; //standard row height
//get the row height
$dim = $sheet->getRowDimension($row)->getRowHeight();
//get special cell heights (non standard)
if($dim != -1){
$height=$dim;
}
//add height for line to pageheight = get current used space
$pageHeight = $pageHeight + $height;
//Check if the space is still in the range of page
$leftOverSpace = $pageMaxHeight-$pageHeight;
//Change $pageClearance to your preferd space before footer
if( $leftOverSpace < $pageClearance){
//Set pagebraek
$sheet->setBreak('A'.$row, \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::BREAK_ROW);
//Reset page height
$pageHeight=$reset;
//Add page header to new page
createHeader($sheet, $row+1, $headeritems);
}
}
//Creates a header for every page
function createHeader($sheet, $row, $texts){
$count = $row;
// Iterate trough the header text array
foreach($texts as $text){
//Insert a new line with header
$sheet->insertNewRowBefore($count, 1);
//Do your header stuff here
$count++;
}
//Add two lines after the header
$sheet->insertNewRowBefore($count, 2);
//Return row number
return $count;
}
?>
Place not that the calculation is not 100% exact and that you must adapt this to your code.
i'm developin an app that sholud create a pdf document with more than one page, my problem is that i found the way to add pages when needen but after the break page it doesn't write.
So the result is a pdf with 8 pages where 7 are blank and only one, the first page that in the document is the last, is correctly writed.
THIS IS MY CODE:
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Helvetica','',10);
$pdf->SetXY(20,20);
$pdf->AcceptPageBreak();
$pdf->SetAutoPageBreak(true);
//PDF content before table
$pdf->Write(14,"Resoconto dell'applicazione EBI dell'ultimo mese:");
$pdf_table=new FPDF_Table($pdf);
//$pdf_table->setDefaultCellWidth(50);
//echo "<br>";
//echo "------------------------------------------- <br>";
$i=0;
$righe=0;
while (...) {
if ($righe % 20 === 0) {
$pdf->AddPage();
$pdf->SetFont('Helvetica','',10);
$pdf->SetXY(20,20);
}
$righe++;
$pdf->Write(...);
}
How can i solve this?
Thank's
This is my code, and when I have more than 4 images, the images go off the screen like this
http://prntscr.com/64l0sw
How would I do it so after the first 4 images, it starts the new line of images instead of using my code to make a new page after every 4 images? My code is below
http://pastebin.com/rFg0CmWe
You can add a counter to your while-loop and check if there are 4 images and then add a break:
$i = 0;
while ($item = mysql_fetch_assoc($getItems)){
if(($i % 4) == 0){
//add page break e.g. new row in table or <br>
}
$i++;
}
This could be done easily on client side. You can use responsive grid for example:
flex-gs
Bootstrap 3
Gumby
Skeleton
Foundation
Base
Unsemantic
I am new to PHP and, I have a CSV file which, am displaying in my web page. I want the CSV file to be displayed with the pagination option so that the web page would look nice. This is the code I have so far.
<?php
$names = file('demo.csv');
$page = $_GET['page'];
//constructor takes three parameters
//1. array to be paged
//2. number of results per page (optional parameter. Default is 10)
//3. the current page (optional parameter. Default is 1)
$pagedResults = new Paginated($names, 20, $page);
echo "<ul>";
while($row = $pagedResults->fetchPagedRow()) {
//when $row is false loop terminates
echo "<li>{$row}</li>";
}
echo "</ul>";
//important to set the strategy to be used before a call to fetchPagedNavigation
$pagedResults->setLayout(new DoubleBarLayout());
echo $pagedResults->fetchPagedNavigation();
?>
However, the CSV file gets displayed with the commas in the screen. Let us consider the below example. Let's assume we have 40 records in my csv file. The contents of the CSV file are as below.
Author1,Name1,Name2,email
1,John,Smith,john.smith#gmail.com
2,Jack,Gibbs,Jack.gibbs#gmail.com
3,Mike,Dell,Mike.dell#gmail.com
and so on.
In my web page, I am getting the output in 2 pages (as I have set my pagination option to display 20 records in each page.
$pagedResults = new Paginated($names, 20, $page);
The output however still contains the comma from the original CSV file. I want my output to be like below.
First Page:
Author1 Name1 Name2 Email
1 John Smith john.smith#gmail.com
and so on.
Second Page:
Author1 Name1 Name2 Email
and so on.
This is because you are pulling the line as a row, but not parsing the line and outputting it cleanly.
The easiest solution is to parse it and then output it separated by div's with each row wrapped in a div. Then make the whole thing pretty with CSS.
Like this:
<?php
$names = file('demo.csv');
$page = $_GET['page'];
/*
Constructor takes three parameters:
1. array to be paged
2. number of results per page (optional parameter. Default is 10)
3. the current page (optional parameter. Default is 1)
*/
$pagedResults = new Paginated($names, 20, $page);
echo "<div class='CSVtable'>";
while($row = $pagedResults->fetchPagedRow()) {
$data = str_getcsv($row);
$dataRow = implode("</div><div class='csvCol'>", $data);
echo "<div class='csvRow'><div class='csvCol'>{$dataRow}</div>";
}
echo "</div>";
//important to set the strategy to be used before a call to fetchPagedNavigation
$pagedResults->setLayout(new DoubleBarLayout());
echo $pagedResults->fetchPagedNavigation();