PHP code example of yii2tech / html2pdf
1. Go to this page and download the library: Download yii2tech/html2pdf library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
yii2tech / html2pdf example snippets
return [
'components' => [
'html2pdf' => [
'class' => 'yii2tech\html2pdf\Manager' ,
'viewPath' => '@app/views/pdf' ,
'converter' => 'wkhtmltopdf' ,
],
],
...
];
$html = <<<HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p>Simple Content</p>
</body>
</html>
HTML;
Yii::$app->html2pdf
->convert($html)
->saveAs('/path/to/output.pdf' );
Yii::$app->html2pdf
->convertFile('/path/to/source.html' )
->saveAs('/path/to/output.pdf' );
Yii::$app->html2pdf
->convertFile('/path/to/source.html' , ['pageSize' => 'A4' ])
->saveAs('/path/to/output.pdf' );
return [
'components' => [
'html2pdf' => [
'class' => 'yii2tech\html2pdf\Manager' ,
'viewPath' => '@app/pdf' ,
'converter' => [
'class' => 'yii2tech\html2pdf\converters\Wkhtmltopdf' ,
'defaultOptions' => [
'pageSize' => 'A4'
],
]
],
],
...
];
Yii::$app->html2pdf
->render('invoice' , ['user' => Yii::$app->user->identity])
->saveAs('/path/to/output.pdf' );
$context = $this ->context;
$context->layout = 'layouts/payment' ;
$context->pdfOptions = [
'pageSize' => 'A4' ,
];
php composer.phar