2014-07-15 44 views
1

我正在努力为生成的PDF创建重复背景。wkhtmltopdf所有页面上的重复背景图像

我有我试图

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

回答

0

我设法 “解决” 问题。

基于这个问题Why doesn't wkhtmltopdf page-break-after have any effect?我实际上强迫页面在一个固定点后手动分解并创建一个具有相同背景的新页面。

OK,这是一个 “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> 
...