Page 1 of 1
[SOLVED] FPDF
Posted: Wed Apr 26, 2006 4:17 am
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.

Posted: Wed Apr 26, 2006 5:52 am
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");
Posted: Thu Apr 27, 2006 3:44 am
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.
Posted: Thu Apr 27, 2006 4:30 am
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.
Posted: Thu Apr 27, 2006 4:45 am
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?
Posted: Thu Apr 27, 2006 5:06 am
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.
Posted: Thu Apr 27, 2006 5:41 am
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.
