how to skip a line in a while - php

I'm trying to convert php into pdf with the function FPDF but I did a select on my data base and I would like to have all the element of this select in PDF:
$query="select organisme,id from client";
$resultats=$db->query($query);
$pdf=new FPDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->Cell(20,6,'ID',1,0,'C',100);
$pdf->Cell(70,6,'mes organismes',1,0,'C',1);
$pdf->SetFont('Arial','',10);
while ($row = $resultats->fetch(PDO::FETCH_ASSOC))
{
$pdf->Cell(20,6,utf8_decode($row['id']),1,0,'C',1);
$pdf->Cell(70,6,$row['organisme'],1,0,'C',1);
}
$pdf->Output();
?>
But the problem is that I got the ID and organisme but I have a problem :
i would like to know how I do to skip line into all new id and organisme
Thanks

FPDF's Ln() function performs a line break.
$pdf->Ln();
Add this line below your $pdf->Cell() function calls, both for the header row and inside the while loop.

Related

How to create a pdf key tags in php

May you please help is my first time doing PDF. I want to create a key tags that will fill in the whole PDF so that I can be able to cut them when i print it. I am failing to place a border outside the text to make a square or rectangle. The first three text must be bold the last test not bold.
I want to create something like this:
<?php
$root =realpath($_SERVER['DOCUMENT_ROOT']);
require($root.'/#services/fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Line(10,10,45,10);
$pdf->Line(10,10,10,25);
$pdf->Line(10,10,45,10);
$pdf->SetFont('Arial','B',8);
$pdf->Write(0.1,"Block E",0,'C');
$pdf->Ln(3);
$pdf->SetFont('Arial','B',8);
$pdf->Write(0.1,"Block / Unit - Area",0,'C');
$pdf->Ln(3);
$pdf->SetFont('Arial','B',8);
$pdf->Write(0.1,"Floor",0,'C');
$pdf->Ln(3);
$pdf->SetFont('Arial','',8);
$pdf->Write(0.1,"Door No. Door No",0,'C');
$pdf->Output();
?>

FPDF break page error

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

Unable to output MySQL data to FPDF table

I've tried the tutorials on fpdf and searched all over for helpful code. And I found what I thought would do the trick here on SO. That said, following the example here didn't produce good results. I definitely need help with this.
Here's my code:
<?php
require_once '../root_login.php';
require('fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
//$this->Image('images/bg_all.jpg',10,6,30);
// Arial bold 15
$this->SetFont('Times','B',20);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(40,10,'B A S E B A L L',0,0,'C');
// Line break
$this->Ln(6);
// Arial bold 15
$this->SetFont('Arial','B',9);
$this->Cell(200,10,'LITTLE LEAGUE ROSTERS',0,0,'C');
$this->Ln(20);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',8);
$stmt = $db->prepare('SELECT fname, lname
FROM rosters
ORDER BY lname');
$stmt->execute();
$result = $stmt->fetchALL(PDO::FETCH_ASSOC);
foreach($result as $row) {
$pdf->Cell(0,10,'F NAME:', $row['fname']);
$pdf->Ln();
$pdf->Cell(0,5,'L NAME:', $row['lname']);
$pdf->Ln();
}
$pdf->Output();
?>
You can view the output here
Does anyone see what I'm doing wrong? And why are those lines being drawn? Thanks.
In FPDF you should fully define all cell options and your text for the cell should be in the third position:
$pdf->Cell(0,5,'L NAME:'. $row['lname'], 0, 0, 'L');
------------------------^
Note the concatenation. Then follow up with the border(0 for no border, which should be the default), the next line definition (Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.) and the alignment of the text in the cell.
Joining the string and doing it with less parameters?
foreach($result as $row) {
$pdf->Cell(0,10,'F NAME: '.$row['fname']);
$pdf->Ln();
$pdf->Cell(0,5,'L NAME: '.$row['lname']);
$pdf->Ln();
}

How to add table header to all pages using FPDF and WriteHTML

I'm generating a large table (more than one page) using FPDF in Landscape mode and need to add table header in all pages. How can I do that? Here is my code:
require('html_table.php');
$pdf=new PDF();
$pdf->AddPage('L');
$pdf->SetFont('Arial','',12);
$html='<table border="1">';
for ($i=0; $i<300; $i++)
{
$html.='<tr><td>hello</td><td>hello</td><td>hello</td><td>hello</td></tr>';
}
$html.='</table>';
$pdf->WriteHTML($html);
$pdf->Output("reporte_semanal_".date("d").date("m").date("Y")."_".date("H")."H".date("i")."M".date("s")."S".".pdf", "D");

FPDF Header Question - Driving me crazy!

I am trying to generate a PDF that outputs Item Names onto a template PDF (using FPDI) with the Username listed on the top of each page. Every user can have a different number of items (i.e. if there are 1-4 items, only output one page; if there 5-8 items, output two pages, etc.)
Here is an example of what I am trying to do: http://www.mediafire.com/?k2ngmqm1jmm
This is what I have so far. I am able to get all of the spacing to work by setting a TopMargin, but this doesn't allow me to put the Username header in.
<?php
require_once('auth.php');
require_once('config.php');
require_once('connect.php');
$username=$_GET['username'];
$sql="SELECT * FROM $tbl_items WHERE username='$username'";
$result=mysql_query($sql);
require_once('pdf/fpdf.php');
require_once('pdf/fpdi.php');
$pdf =& new FPDI();
$pdf->SetTopMargin(30);
$pdf->AddPage('L', 'Letter');
$pdf->setSourceFile('../pdf/files/chart_template.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial', 'B');
$pdf->SetFontSize(7);
while($rows=mysql_fetch_array($result)){
$pdf->Cell(20,5,$rows['itemname'],0,0,'C');
$pdf->Ln(45);
}
$pdf->useTemplate($tplIdx);
$pdf->Output('file.pdf', 'I');
?>
Please help!
I've done it previously using the 'header' class extension:
class PDF extends FPDF
{
function Header()
{
//Select Arial bold 15
$this->SetFont('Arial','B',15);
//Move to the right
$this->Cell(80);
//Framed title
$this->Cell(30,10,'Title',1,0,'C');
//Line break
$this->Ln(20);
}
Have a look at the tutorial which explains the header usage at : http://www.fpdf.org/en/tutorial/tuto2.htm

Categories