I am struggling to make a repetitive background for a generated PDF.
I have a certificate that is automatically generated and certificate design has a frame that should repeat on all the pages...
I tried
.main_container{
background: url({{ resourceDir ~ 'img/certificate_margin.jpg' }}) 0 0;
padding-top:15px;
z-index: 99;
background-size: cover;
width:658px;
height:975px;
}
but after the first page is displayed I only get the content and a white page. Did anyone managed to solve this issue some how? Or is it even possible to do it?
my config file:
knp_snappy:
pdf:
enabled: true
binary: "%wkhtmltopdf_binary_path%"
options:
page-size: A4
dpi: 150
image-dpi: 150
encoding: utf-8
and generation code:
$unsignedPdfContent = $this->snappy->getOutputFromHtml(
$this->templating->render(
$this->getTemplate(), [
'certificate' => $this->certificate,
'resourceDir' => __DIR__.'/../Resources/public/'
]
)
);
After thinking about this problem, I recommend just delegating out to something like
pdftk
and use the same logic for watermarks for a recurring background image.https://www.pdflabs.com/docs/pdftk-man-page/#dest-op-multistamp
I managed to "solve" the problem.
Based on this question Why doesn't wkhtmltopdf page-break-after have any effect? I actually forced the page to manually break after a fixed point and create a new page with the same background.
OK, it's a "hackish" way but it did the job...
now my code looks like this
CSS
And the twig