Integrate TCPDF into a Yii2 Advanced application
To integrate TCPDF into a Yii2 Advanced application, follow these steps:
Step 1: Install TCPDF via Composer:
In the root directory of your Yii2 Advanced application, run the following command:
composer require tecnickcom/tcpdf
Step 2: Create a new php file or use an existing one to generate PDFs.
Here is an example of how to use TCPDF in a Yii2:
$rootPath = Yii::getAlias('@vendor');
require_once $rootPath . '/autoload.php';
require_once $rootPath . '/tecnickcom/tcpdf/tcpdf.php';
$pdf = new TCPDF();
$pdf->SetCreator('Your Name');
$pdf->SetAuthor('Your Name');
$pdf->SetTitle('Sample PDF');
$pdf->SetSubject('Sample PDF');
$pdf->SetKeywords('TCPDF, PDF, Sample');
$pdf->AddPage();
$pdf->SetFont('times', 'B', 16);
$pdf->Cell(40, 10, 'Hello World!');
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="example.pdf"');
ob_end_clean();
$pdf->Output('example.pdf', 'I');
Komentar
Posting Komentar