2014-07-15 48 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> 
...