Forum Moderators: coopster
<?php
require('fpdf.php');class PDF extends FPDF
{
//Page header
function Header()
{
//Logo
$this->Image('logo_pb.png',10,8,33);
//Arial bold 15
$this->SetFont('Arial','B',15);
//Move to the right
$this->Cell(80);
//Title
$this->Cell(30,10,'Title',1,0,'C');
//Line break
$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','',12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();
?>
It prints the printing line number , however i want to print the data in $row['content']. How to do it? Where should i write it?
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1);
That loops through 40 lines.
Start by changing 40 to the real line-number count....
$lines=explode("\n",$row[content]); //<< split into lines
for($i=1;$i<=sizeof($lines);$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1); Now, add in the right line:
$lines=explode("\n",$row[content]); //<< split into lines
for($i=1;$i<=sizeof($lines);$i++)
$pdf->Cell(0,10,$i.' '.$lines[$i],0,1);
i want a php (whose contents are in mysql db) and are accessed as $row['title'], $row['content'] etc; to be converted into pdf. I am using fpdf for doing so. In it's tutorial they have given the following code for header, footer and content generation.
[php]<?php
//$lastPage = ceil($numRows/$perPage);
// Database Connection
include("$_SERVER[DOCUMENT_ROOT]/includes/connect.inc.php");
include("$_SERVER[DOCUMENT_ROOT]/includes/stripgpcslash.inc.php");
//pdf
include('../fpdf.php');
$sql = mysql_query("SELECT * FROM wow WHERE `trusted` = 0 ORDER BY `id` ASC LIMIT $from, $max_results");
while($row = mysql_fetch_array($sql)){
class PDF extends FPDF
{
//Page header
function Header()
{
//Logo
$this->Image('logo_pb.jpg',10,8,33);
//Arial bold 15
$this->SetFont('Arial','B',15);
//Move to the right
$this->Cell(80);
//Title
$this->Cell(30,10,$row['title'],1,0,'C');
//Line break
$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','',12);
$pdf->Cell(0,10,$row['content'],0,1);
$pdf->Output();
//pdf
}
mysql_close($con);
?>[/php]
Instead of title i want to print the $row['title'] . hen i use the above code it says
Notice: Undefined variable: row in c:\program files\easyphp1-8\www\fpdf\tutorial\pages.php on line 55
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\fpdf\tutorial\pages.php:55) in c:\program files\easyphp1-8\www\fpdf\fpdf.php on line 1022
FPDF error: Some data has already been output to browser, can't send PDF file. How do i print the $row['title'] instead of static 'title'?