Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a solution for pdf template in PHP?

Tags:

php

pdf

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

is it viable ?

like image 293
user198729 Avatar asked Jan 23 '23 01:01

user198729


2 Answers

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
like image 143
user187291 Avatar answered Jan 24 '23 16:01

user187291


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!!!

like image 27
Knowledge Craving Avatar answered Jan 24 '23 16:01

Knowledge Craving