tags:

views:

84

answers:

3

I need to generate quotes in pdf format by PHP, with a template and dynamic values retrieved from database.

is it viable ?

+4  A: 

yes, fpdf + fpdi worked for me

basically, you create your pdf template first, then load it into the new FPDI object and use FPDF functions to draw "over" the template - much like photoshop layers work.

$pdf = new FPDI(); 

$pdf->setSourceFile('template.pdf'); 
$tpl = $pdf->importPage(1); 
$pdf->addPage(); 
$pdf->useTemplate($tpl); <- template is imported

$pdf->setXY(10, 20);
$pdf->write(100, "Hi there"); <- write or draw something on the template

$pdf->output('newpdf.pdf', 'D'); <- ready, save or output your pdf
stereofrog
My team is using FPDF to some success, though I haven't coded against it yet.
Adam Backstrom
Do you mean I need these two libs to create a customized pdf,or ...can you demonstrate ?
see update.....
stereofrog
Last but no least,is it free?Seems not ..?
what makes you think so? both libs are open-source.
stereofrog
Good !But I want the dynamic text be added like this way:`print("this is your product:%s",$name)`.Seems it's not the case in the demo.
sprintf is your friend
stereofrog
No,in a photoshop manner,I don't think it can handle the overflow issue,I need it to wrap around instead of go out of view.
+2  A: 

Try the DOMPDF. It's very good & easy to use, and has got some very useful APIs. I have used it twice, and it really amazes me as to what not you can do.

Really, you can set multiple pages in the on-the-fly created PDF, with resized images acting as catalog products.

It has a very good Documentation, with examples shown. If you have any problems integrating it, feel free to post your question here, and the users will be proactive in answering your questions.

DOMPDF is an awesome cool stuff. I think that it has also won some awards, for its sheer coding standard. Check out yourself, for more!!!

Knowledge Craving
A: 

If you can afford the licensing costs, PDFLIB has a nice templating system they call "blocks". You draw the blocks onto the source template in Acrobat, assign it a name, and then in the PHP code it's a simple matter of issuing a "fill this block with the following text/image/eps".

Once all the housekeeping code of opening the template/loading fonts/etc...is completed, the fill-in-the-blanks codes boils down to:

PDF_fill_textblock($pdf, $pagehandle, $blockname, "Text to insert", 'fitting method arguments');
PDF_fill_imageblock($pdf, $pagehandle, $blockname, $imagehandle, 'fitting method arguments');
PDF_fill_pdfblock($pdf, $pagehandle, $blockname, $pdfhandle, 'arguments here');
Marc B
No I can't afford it..