Is there a solution for pdf template in PHP?
I need to gen开发者_Python百科erate quotes in pdf format by PHP, with a template and dynamic values retrieved from database.
is it viable ?
UPDATE: i see people upvoting this recently and wanted to add that wkhtmltopdf might be a better option for most applications.
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
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!!!
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');
精彩评论