Pdf generation for various usages
The recommended way to install the extension is using composer.
Run the following command within your Composer based TYPO3 project:
composer require peterbenke/pb-pdf
Download and install the extension with the extension manager module.
<?php
namespace [YourVendor]\[YourExtension]\[...];
use PeterBenke\Pdf\Service\PdfService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class YourClass
{
public function yourFunction()
{
$absoluteJobPdfPath = '/var/www/html/fileadmin/user_upload/your-pdf-file.pdf';
$assign = [];
// Create instance
/** @var PdfService $pdfService */
$pdfService = GeneralUtility::makeInstance(
PdfService::class,
'your_extension_key', // extension key
'/Resources/Private/Templates/Pdf/your-template.html', // template path
$absoluteJobPdfPath, // absolute! pdf path to pdf file
null, // tmp directory, if empty => '/tmp' will be set
$assign // optional assign array (fluid)
);
// Create pdf file
try{
$pdfService->create();
}catch(Exception $e){
echo $e->getMessage();
}
}
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{title}</title>
<link rel="stylesheet" type="text/css" href="[absolute_path_to_css_file]" />
</head>
<body>
...
</body>
</html>