I am trying to include TCPDF library in Zend2. but i am not able to get success. Please and any one give the solution to fix this issue.
Thanks Siva
Try to use Composer . Add the line below into composer.json
file's require
section in your project root:
"require": {
"php" : ">=5.4",
"zendframework/zendframework" : "2.3.1",
"tecnickcom/tcpdf" : "dev-master" <<<-- this line --
},
Open your terminal (command line) and type:
cd /path/to/your/project/root
php composer.phar selfupdate
php composer.phar update
And anywhere in your app:
$pdf = new \TCPDF();
Thats it.
add the "tecnickcom/tcpdf" : "dev-master" in the composer.json
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-component-installer": "^1.0 || ^0.7 || ^1.0.0-dev@dev",
"zendframework/zend-servicemanager": "^3.3",
"tecnickcom/tcpdf" : "dev-master"
},
run the composer update in the root of your project directory
add the use \\TCPDF; top of your controller file
paste the following code in your function
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->AddPage();
$html ="<style>
th{border:0.5px solid #C0C0C0;background-color:rgb(44,126,193); font-size: 9pt;text-align: center;color:#FFFFFF;font-weight:bold;}
td{ vertical-align: middle;padding-top:5px;border:0.5px solid #C0C0C0;padding:5pt;color:#000000;background-color:#FFFFFF;font-size: 8pt;text-align: center;}
</style>
<table>
<thead>
<tr nobr=”true”><th>Id</th><th>Name</th></tr>
</thead><tbody>
<tr nobr=”true”>
<td>1</td>
<td>Senta</td>
</tr>
</tbody>
</table>";
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
$pdf->Output('example_006.pdf', 'I');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.