Welcome to WebmasterWorld Guest from 54.198.93.179

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP to PDF using fPDF

     
5:21 am on Aug 27, 2007 (gmt 0)

5+ Year Member



Hi ,
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
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?

5:48 am on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member




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);
6:43 am on Aug 27, 2007 (gmt 0)

5+ Year Member



Not able to print row['title']

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'?

7:23 am on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That line is outside of your $row= loop. Check your logic.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month