Thanks for another great module @bernhard
Wanted to share my experiences changing from Pages2PDF to RockPdf. Wasn't quite as straightforward as I'd hoped. Such is life, but I got there. Pages2Pdf uses mPDFv5+ while RockPdf uses mPDFv7+ and I needed some of the newer features.
Things Iearned along the way:
1. If you need to use @page, you lose everything in the template
$pdf->set('header', '...');
settings. This has nothing to do with RockPdf but a 'feature' of mPDF
2. It's much easier to add custom fonts to RockPdf than Pages2PDF
3. You can display images in a circle using background-image but they don't print so that's not helpful, LOL
This is NOT a full tutorial but hopefully will give you some pointers on how I got RockPdf working for a fairly specific PDF design.
RockPdf template settings:
<?php
$pdf = $modules->get('RockPdf');
$pdf->settings([
'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [
"montserrat" => [
'R' => "montserrat-regular.ttf",
'B' => "montserrat-bold.ttf",
],
"montserratlight" =>[
'R' => "montserrat-light.ttf"
],
"montserratthin" => [
'R' => "montserrat-thin.ttf"
]
],
'defaultheaderline' => 0,
'font_size' => 9,
'mode' => 'utf-8',
'font' => 'montserrat',
'page_format' => 'A4',
]);
$css = wireRenderFile($config->paths->templates . 'RockPdf/styles-v3.css');
$pdf->write("<style>" . $css . "</style>");
$body = wireRenderFile($config->paths->templates . 'RockPdf/profile_pdf_cv-v3.php');
$pdf->write($body);
$pdfFile = $sanitizer->pageName($profile->title) . "-" . $profile->id . ".pdf";
$pdf->show($pdfFile);
die();
// Remove old Pages2PDF settings
// $mpdf->markupMain = $config->paths->templates . 'RockPdf/profile_pdf_cv-v3.php';
// $mpdf->markupHeader = $config->paths->templates . 'RockPdf/_header-v3.php';
// $mpdf->markupFooter = $config->paths->templates . 'pages2pdf/_footer-v2.php';
// $mpdf->cssFile = $config->paths->templates . 'RockPdf/styles-v3.css';
// $mpdf->pageOrientation = 'P';
// $mpdf->pageFormat = 'A4';
// $mpdf->topMargin = 9.5;
// $mpdf->rightMargin = 0;
// $mpdf->bottomMargin = 9;
// $mpdf->leftMargin = 0;
// $mpdf->headerMargin = 0;
// $mpdf->footerMargin = 0;
// $mpdf->fontSize = 9;
// $mpdf->mode = 's';
// $mpdf->font = 'montserrat';
Header code:
<div style="
background-color: #007ee5;
height: 10mm;
margin: 0;
top: 0;
left: 0;
right: 0;
width: 100%;
">
</div>
Page layout code:
<?php
// header is the same on all pages but need more spacing on all pages except the first
$header = wireRenderFile($config->paths->templates . 'RockPdf/_header-v3.php');
?>
<htmlpageheader name="myHeaderFirst" style="display:none">
<?=$header?>
</htmlpageheader>
<htmlpageheader name="myHeader" style="display:none">
<?=$header?>
</htmlpageheader>
<sethtmlpageheader name="myHeaderFirst" value="on" show-this-page="1" />
<sethtmlpageheader name="myHeader" value="on" />
<div class="user-dets">
CSS:
/*
Additional fonts added to:
site/assets/RockPdf/fonts
*/
@page {
margin: 15mm 0 0 0; /* <any of the usual CSS values for margins> */
/*(% of page-box width for LR, of height for TB) */
margin-header: 0; /* <any of the usual CSS values for margins> */
margin-footer: 9mm; /* <any of the usual CSS values for margins> */
marks: none;/*crop | cross | none*/
header: html_myHeader;
}
@page :first {
margin: 9.5mm 0 0 0; /* <any of the usual CSS values for margins> */
/*(% of page-box width for LR, of height for TB) */
margin-header: 0; /* <any of the usual CSS values for margins> */
margin-footer: 9mm; /* <any of the usual CSS values for margins> */
marks: none;/*crop | cross | none*/
header: html_myHeaderFirst;
}
Hope this is useful.
Cheers
psy