PHP code example of geniv / nette-wrapper-mpdf
1. Go to this page and download the library: Download geniv/nette-wrapper-mpdf 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');
/* Start to develop here. Best regards https://php-download.com/ */
geniv / nette-wrapper-mpdf example snippets
public function createComponentWrapperMpdf(WrapperMpdf $wrapperMpdf): WrapperMpdf
{
$wrapperMpdf->setTemplatePath(__DIR__ . '/templates/Project/pdf.latte');
$wrapperMpdf->setTemplatePathHeader(__DIR__ . '/templates/pdfHeader.latte');
$wrapperMpdf->setTemplatePathFooter(__DIR__ . '/templates/pdfFooter.latte');
$wrapperMpdf->setTemplatePathStyle(__DIR__ . '/templates/pdfStyle.latte');
$wrapperMpdf->setTitle('Titulek');
// $wrapperMpdf->setFormat('A4-L');
// $wrapperMpdf->setFormat('A4');
$wrapperMpdf->addFontDirectory(__DIR__ . '/../components/mPDF/ttfonts');
$wrapperMpdf->addFont('roboto', [
'R' => 'Roboto-Regular.ttf',
'B' => 'Roboto-Bold.ttf',
'I' => 'Roboto-Italic.ttf',
'BI' => 'Roboto-BoldItalic.ttf',
]);
$wrapperMpdf->addConfig('setAutoBottomMargin', 'stretch');
$wrapperMpdf->addConfig('autoMarginPadding', -9);
// $wrapperMpdf->setLogger($logger);
// $wrapperMpdf->setShowImageErrors(true);
// $wrapperMpdf->setDebug(true);
// $wrapperMpdf->setBacktrackLimit('5000000');
return $wrapperMpdf;
}
public function actionPdf()
{
$wrapper = $this['wrapperMpdf'];
$wrapper->setTemplatePath(__DIR__ . '/templates/pdf.latte');
// $wrapper->setFormat('A4-L');
$wrapper->setFormat('A4');
$title = 'title of page';
$wrapper->setTitle($title);
$wrapper->addVariableTemplate('title', $title);
$wrapper->render();
// $wrapper->render(true); // preview
// $wrapper->render(false, 'mpdf.pdf'); // save to file
// $pdf = $wrapper->render(false, null, \Mpdf\Output\Destination::STRING_RETURN); // return to variable
$this->terminate();
}
json
"php": ">=7.0",
"nette/nette": ">=2.4",
"geniv/nette-general-form": ">=1.0",
"mpdf/mpdf": ">=7.1"