2017-10-01 9 views
1

Ich versuche, PDF aus HTML mit CSS-Stilen zu generieren,PHP dompdf funktioniert nicht mit CSS

Ich verwende dompdf für diese. In CSS gibt es auch Schwimmer.

Dies ist meine CSS und HTML-Code:

$dompdf = new DOMPDF(); //create object 
//load html with css 
$dompdf->loadHtml('<html> 
<head> 
<style> 
#first_head,#second_head,#content_invoice{width: 100%;} 
.has-65 { 
    width: 65%; 
    float:left; 
} 
#product_invoice_table tr th:last-child, #product_invoice_table tr td:last-child { 
    text-align: right; 
} 
.has-35 { 
    width: 35%; 
    float:right; 
} 
.has-55 { 
    width: 55%; 
} 
.has-45 { 
    width: 45%; 
} 
.clearFix{ 
    float:none; 
    clear:both; 
} 
#second_head{ 
    margin-top: 100px; 
} 

#template_invoice{ 
    padding: 50px 80px 50px 80px; 
    margin: 0 auto; 
    margin-top: 30px; 
    margin-bottom: 30px; 
    font-size: 20px; 
    color: #000!important; 
    font-family: Arial,serif!important; 
} 
#content_invoice{ 
    width: 100%; 
    float: left; 
    margin-top: 150px; 
} 

#product_total_info{ 
    float: right; 
    margin-top: 100px; 
}... 
</style> 
</head> 
<body> 
<div id="template_invoice"> 
    <div id="first_head"> 
     <div id="logo_invoice" class="has-65"> 
      <img src="logo.PNG" width="280px"> 
     </div> 
     <div id="main_header_info" class="has-35"> 
     mandelaugengroup gmbh 
Schaffhauserstrasse 611 
CH - 8052 Zürich 
Tel.: +41 79 205 05 05 
[email protected] 
www.babboe.ch 
MWST/UID-Nr. CHE-254.427.754 
     </div> 
    </div> 
    <div class="clearFix"></div> 
    <div id="second_head"> 
     <div id="lead_address" class="has-65"> 
      <span id="lead_name">ghmgmgm</span><br> 
      <span id="lead_street">mhgmhm</span><br> 
      <span id="lead_postcode_city">mbmbmjggjg</span><br> 
     </div> 
     <div id="lead_invoice_info" class="has-35"> 
      <div class="span_padding_invoice"> 
      <span class="invoice_main_span">Rechnungs-Nr.</span> 
      <span id="lead_rechnungs_nr" class="right-clmn-span">jghghjgh</span> 
      <br> 
      </div> 
      <div class="span_padding_invoice"> 
      <span class="invoice_main_span">Kunden-Nr.</span> 
      <span id="lead_kunder_nr" class="right-clmn-span">ghjgvj</span> 
      <br> 
       </div> 
      <div class="span_padding_invoice"> 
      <span class="invoice_main_span">Datum</span> 
      <span id="invoice_datum" class="right-clmn-span">hhhhhhh</span> 
      <br> 
       </div> 
      <div class="span_padding_invoice"> 
      <span class="invoice_main_span">Fallig am</span> 
      <span id="invoice_falling_am" class="right-clmn-span">bjbbb</span> 
      <br> 
       </div> 
      <div class="span_padding_invoice lead_total_container"> 
       <span class="invoice_main_span total_bold">Total</span> 
       <span id="lead_total" class="right-clmn-span">iljkkj</span> 
       <br> 
      </div> 
     </div> 
    </div> 
    <div id="content_invoice"> 
    ... 
     <table id="product_invoice_table" width="100%"> 
     .... 
     </table> 
    </div> 
    <div class="has-65"></div> 
    <div id="product_total_info" class="has-35"> 
     <div class="span_padding_invoice lead_total_container"> 
     <span class="invoice_main_span">Total exkl.MWST</span> 
     <span class="right-clmn-span">CHF <span id="total_sum"></span></span> 
     </div> 
     <div class="span_padding_invoice"> 
     <span class="invoice_main_span" id="mwst_num"></span> 
     <span class="right-clmn-span">CHF <span id="total_percant"></span></span> 
     <br> 
      </div> 
     <div class="span_padding_invoice lead_total_container_bold"> 
     <span class="invoice_main_span">Total</span> 
     <span class="right-clmn-span">CHF <span id="total_end"></span></span> 
      <br> 
      </div> 
    </div> 
    <div id="footer_invoice"> 
    ... 
    </div> 
</div> 
</body> 
</html>'); 
$dompdf->render(); 
$dompdf->stream("hello.pdf"); 

Aber mein css funktioniert nicht gut. Ich füge css als hinzu. ich dieses Ergebnis:

result

So wie kann ich dieses Problem lösen? Vielleicht muss ich einige Einstellungen für meine CSS oder Einstellungen für die Seite festlegen? Danke für jede Hilfe.

+0

Haben Sie eine Lösung gefunden? War es das Float-Attribut? –

Antwort

0

Ich bin ziemlich sicher, dass float die Ursache des Problems ist

auf der dompdf Version Je Sie def("DOMPDF_ENABLE_CSS_FLOAT", true); in dompdf_config.inc.php verwenden können, aber das ist keine gute Praxis

Ich würde vorschlagen Verwenden Sie display:inline-block oder sogar position:absolute, die vollständig kompatibel sind.