[SOLVED] FPDF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

[SOLVED] FPDF

Post by rsmarsha »

Anyone used FPDF?

I'm having trouble getting a variable to show inside a cell with text.

Code: Select all

//tried this which doesn't work
$pdf->Cell(0,0,'Quote Number: '.$number.'',0,0,'C');

//this works but i have to set a - value to move the number to the right location
$pdf->Cell(0,0,'Quote Number: ',0,0,'C');
$pdf->Cell(-140,0,$number,0,0,'C');
With the 2nd bit of code i have to set Cell(-140,0,$number,0,0,'C'), to get it to move the number to the text. The problem then is it's not really centered.

If anyone has experience of using fpdf, help would be great. :)
Last edited by rsmarsha on Thu Apr 27, 2006 5:41 am, edited 1 time in total.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

I think the problem with your fist bit of code is that you have tried to put your variable between quotes instead of just appending it to your quoted string:

Code: Select all

//tried this which doesn't work
$pdf->Cell(0,0,'Quote Number: '.$number.'',  0, 0, 'C');
which should be

Code: Select all

$pdf->Cell(0,0,'Quote Number: '.$number, 0, 0,'C');
This is a bit of code from one of my fpdf document generators which works. I've used double quotes around the strings but other than that its the same.

Code: Select all

$this->Cell(10,10,"Document prepared: ".date('d/m/Y'), 0 ,0 ,"R");
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks. :)

Another question, i have :

Code: Select all

$pdf->Cell(10,5,'Product Category',0,0);
$pdf->Cell(100,5,'Product Description',0,1,'C');
while ($row = mysql_fetch_assoc($findq))
{
$cat = $row['category_name'];
$prod = $row['product_desc'];
$pdf->Cell(10,5,$cat,0,0);
$pdf->Cell(100,5,$prod,0,1,'C');
}
The left column under the first header is aligned on the left of the cell. When i tried to make the right header and it's text do that it overlapped, so had to centre it. I want the right column of text to be aligned to the left, as the header is.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

off the top of my head, maybe you need to look at the setX() method before creating the cell that you want to be on the right. Look in the doc folder that came with FPDF, its very useful.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks again, perfect. :)

Bit of a different question.

If the pdf from $output is output to the browser. Could i have this output, mailed with php's mail function?
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

I'd use this email class, which I use to send the generated pdfs as attachments. I always generate the actual pdf as a file on the server before redirecting the user to view it in the browser.

http://codewalkers.com/getcode.php?id=430

I think there are newer versions but just to be sure I've included the one that I actually have working at the moment.

You can send emails as html or plain text with an attachment (or multipart/alternative but then you can't use attachments).

If you simply email the $output with mail() I suspect all you would get is pdf code jargon, since email clients don't generally include a pdf reader.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Cracking!

Got it generating as i want, saving the file, emailing it, then deleting the file. :)

Thanks for the help, just need to add the finishing touches to the pdf file now. :)
Post Reply