homepage Welcome to WebmasterWorld Guest from 54.226.166.224
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP to PDF using fPDF
kkonline




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

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?

 

vincevincevince




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


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);

kkonline




msg:3432996
 6:43 am on Aug 27, 2007 (gmt 0)

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

vincevincevince




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved