所有页面上的wkhtmltopdf重复背景图像(wkhtmltopdf repeatitive background image on all pages)

编程入门 行业动态 更新时间:2024-10-27 15:21:44
所有页面上的wkhtmltopdf重复背景图像(wkhtmltopdf repeatitive background image on all pages)

我正在努力为生成的PDF制作重复背景。

我有一个自动生成的证书,证书设计有一个框架,应该在所有页面上重复...

我试过了

.main_container{ background: url({{ resourceDir ~ 'img/certificate_margin.jpg' }}) 0 0; padding-top:15px; z-index: 99; background-size: cover; width:658px; height:975px; }

但在显示第一页后,我只获得内容和白页。 有没有人设法解决这个问题? 或者甚至可以这样做?

我的配置文件:

knp_snappy: pdf: enabled: true binary: "%wkhtmltopdf_binary_path%" options: page-size: A4 dpi: 150 image-dpi: 150 encoding: utf-8

和代码:

$unsignedPdfContent = $this->snappy->getOutputFromHtml( $this->templating->render( $this->getTemplate(), [ 'certificate' => $this->certificate, 'resourceDir' => __DIR__.'/../Resources/public/' ] ) );

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/' ] ) );

最满意答案

我设法“解决”了这个问题。

基于这个问题为什么wkhtmltopdf page-break-after没有任何影响? 我实际上强制页面在固定点之后手动中断并创建具有相同背景的新页面。

好吧,这是一种“hackish”的方式,但它完成了这项工作......

现在我的代码看起来像这样

CSS

.main_container{ background: url({{ resourceDir ~ 'img/certificate_margin.jpg' }}) 0 0; padding-top:15px; padding-left:5px; z-index: 99; background-size: cover; width:652px; height:975px; position:relative; } .break{ display: block; clear: both; page-break-after: always; }

和树枝

... <body> <div class="main_container break" style='position:relative'> first page content {% block body %} {% endblock %} {% include 'BlablaBundle:Pdf:_partial_certificate/_footer_contact.html.twig' with {'page': 'Seite 1/2'} %} </div> <div class="main_container" style='position:relative'> second page content {% include 'BlablaBundle:Pdf:_partial_certificate/_footer_contact.html.twig' with {'page': 'Seite 2/2'} %} </div> </body> ...

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

.main_container{ background: url({{ resourceDir ~ 'img/certificate_margin.jpg' }}) 0 0; padding-top:15px; padding-left:5px; z-index: 99; background-size: cover; width:652px; height:975px; position:relative; } .break{ display: block; clear: both; page-break-after: always; }

And the twig

... <body> <div class="main_container break" style='position:relative'> first page content {% block body %} {% endblock %} {% include 'BlablaBundle:Pdf:_partial_certificate/_footer_contact.html.twig' with {'page': 'Seite 1/2'} %} </div> <div class="main_container" style='position:relative'> second page content {% include 'BlablaBundle:Pdf:_partial_certificate/_footer_contact.html.twig' with {'page': 'Seite 2/2'} %} </div> </body> ...

更多推荐

本文发布于:2023-08-06 15:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   背景   页面   wkhtmltopdf   pages

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!