wkhtmltopdf 水印 背景,所有页面上的wkhtmltopdf重复背景图像

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/'

]

)

);

解决方案

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

...

first page content

{% block body %}

{% endblock %}

{% include 'BlablaBundle:Pdf:_partial_certificate/_footer_contact.html.twig' with {'page': 'Seite 1/2'} %}

second page content

{% include 'BlablaBundle:Pdf:_partial_certificate/_footer_contact.html.twig' with {'page': 'Seite 2/2'} %}

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值