2016-11-05 71 views
0

我想使用dom生成pdf pdfdompdf图像重叠文本pdf生成问题

但是在pdf的标题部分,图像和文本重叠。

无法确定究竟是错在我的代码?

的CodeIgniter控制器功能:

$dompdf = new Dompdf(); 
    $dompdf->set_option('enable_css_float', true); 
    $contxt = stream_context_create([ 
     'ssl' => [ 
      'verify_peer' => FALSE, 
      'verify_peer_name' => FALSE, 
      'allow_self_signed'=> TRUE 
     ] 
    ]); 
    $options = new Options(); 
    $dompdf->setHttpContext($contxt); 
    $dompdf->set_option('isRemoteEnabled', true); 
    $dompdf->set_option('debugKeepTemp', true); 
    $dompdf->set_option('isHtml5ParserEnabled', true); 


    $dompdf->loadHtml($pdfdata); 
    // (Optional) Setup the paper size and orientation 
    $dompdf->setPaper('A4', 'portrait'); 

    // Render the HTML as PDF 
    $dompdf->render(); 
    $output = $dompdf->output(); 

笨查看

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]--> 

    <link rel="stylesheet" href="<?php echo CSS_PATH_BACKEND; ?>bootstrap.min.css"> 
    <style>  
     @page { margin: 20px 30px; } 
     .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{padding:6px;} 
     .table-bordered{border:2px solid #000;} 
     .table-bordered>tbody>tr>td, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>td, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>thead>tr>th{border:2px solid #000;} 
     .list-inline>li{ display: inline-block; 
          padding-right: 35px; 
          padding-left: 35px; 
          padding-top: 10px; 
          font-weight: 700;} 
     body{font-size:13px;} 
     .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{padding:5px 0 5px 10px;} 
     .goods-table td{border:2px solid #000; } 
     thead:before, thead:after { display: none; } 
     tbody:before, tbody:after { display: none; } 
     tbody:before, tbody:after { display: none; } 
     .invoice tr td{} 
     .product_invoice td{padding:4px 5px !important;} 
     li{padding: 10px 0;} 
     li:before{content:''; font-size:60px; line-height:20px; vertical-align:middle;} 
    </style> 
</head> 
<body> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-xs-12"> 
      <table class="table goods-table" style="margin-bottom: 0; font-size: 13px; border-collapse: collapse;"> 
       <tbody> 
       <tr> 
       <td> 
       <div class="invoice-title"> 
        <?php 
        $seg = $this->uri->segment(2); 
        if ($seg == "preview") { 
         ?> 
        <img src="http://www.example.com/images/backend/logo_pdf.png" style="margin: 0 auto;display: block;" width="380px" height="76px" class="text-center" alt="logo"/>  
         <?php 
        } else { 
         ?> 
         <img src="http://www.example.com/images/backend/logo_pdf.png" style="margin: 0 auto;display: block;width:380px;height:76px;" width="380px" height="76px" class="text-center" alt="logo"/>  
        <?php } ?> 




        <p style="padding: 5px 0 0 0;margin: 0;font-size: 13px;text-align: center;" class="text-center">Corporate Office: Some address</p> 
        <p style="padding: 0;margin: 0;font-size: 13px;text-align: center;" class="text-center">Phone: 87945456 &nbsp;&nbsp;&nbsp;Cell: 321456789 &nbsp;&nbsp;&nbsp;Email: [email protected]&nbsp;&nbsp;&nbsp;Website: www.example.com</p> 
       </div> 

       <div class="invoice-title"> 
        <span class="text-center" style="margin: 5px 0 0 0;font-weight:700;text-align: center;display: block;font-size: 18px;">TAX INVOICE CUM CHALLAN</span> 
       </div> 
       </td> 
       </tr> 
       </tbody> 
       </table> 

      </div> 
     </div> 
     <div class="row"> 
      <div class="col-md-12"> 
       <div class=""> 
        <div class=""> 
         <div class="table-responsive"> 
          <!--<table class="table table-condensed">--> 
          <table class="table goods-table" style="margin-bottom: 0; font-size: 13px; border-collapse: collapse;"> 
           <tbody> 
            <tr style="border:2px solid #000;"> 
             <td rowspan="4" style="width:40%;" colspan="2"> 
              <!--StartFragment--> 
              <p style="padding: 0;margin: 0;font-size: 13px;"><span >To,</span></p> 
              <p style="padding: 0;margin: 0;font-weight: 700;font-size: 13px;"><span ><?php echo $customer['name']; ?></span></p> 
              <p style="padding: 0;margin: 0;font-size: 13px;"><span ><?php echo $customer['address']; ?></span></p> 
              <p style="padding: 0;margin: 0;font-size: 13px;"><span ><?php echo $customer['address1']; ?></span></p> 
              <p style="padding: 0;margin: 0;font-size: 13px;"><span ><?php echo $customer['city']; ?></span></p> 
              <p style="padding: 0;margin: 0;font-size: 13px;"><span >Phone No: <?php echo $customer['contact_no']; ?></span></p> 

             </td> 
             <td style="vertical-align:middle;width:30%;border:2px solid #000;">Invoice No: <span style="font-weight: 700;"><?php echo $invoice['invoice_no']; ?></span></td> 
             <td style="vertical-align:middle;width:30%;border:1px solid #000;" colspan="3" >Contact Person: <span style="font-weight: 700;"><?php echo ucwords($customer['contact_person_name']); ?></span></td> 
            </tr> 
            <tr style="border:2px solid #000;"> 
             <td style="vertical-align:middle;">Date: <span style="font-weight: 700;"><?php echo date('d M Y', strtotime($invoice['created_date'])); ?></span></td> 
             <td style="vertical-align:middle;" colspan="3">Mobile No: <span style="font-weight: 700;"><?php echo ucwords($customer['contact_person_no']); ?></span></td> 
            </tr> 
            <tr style="border:2px solid #000;"> 
             <td style="line-height: 1;vertical-align:middle;" rowspan="2">RIN No: <span style="font-weight: 700;">87455454</span></td> 
            </tr> 
            <tr style="border:2px solid #000;"> 
             <td style="line-height: 1;vertical-align:middle;" colspan="3"> VAT No: <span style="font-weight: 700;"></span></td> 
            </tr> 
            <tr style="border:2px solid #000;">            
             <!--<td >Company Executive: <?php echo ucwords($user['fname'] . ' ' . $user['lname']); ?></td>--> 
             <td colspan="1">Date of Activation: <span style="font-weight: 700;"><?php echo date('d M Y', strtotime($invoice['activation_date'])); ?></span></td> 
             <td colspan="3">Next Renewal: <span style="font-weight: 700;"><?php echo date('d M Y', strtotime($invoice['renewal_date'])); ?></span></td> 
            </tr> 

           </tbody> 
          </table> 
          <table width="100%" class="table goods-table invoice" style="margin-bottom: 0; font-size: 12px;  border-top: 1px solid #202020;  "> 
           <tbody> 

            <tr> 
             <td style="font-weight: 700;font-size: 13px;width:10%;">Sr. No</td> 
             <td style="font-weight: 700;font-size: 13px;width:15%;">Software ID</td> 
             <td style="font-weight: 700;font-size: 13px;width:35%;">Description</td> 
             <td style="font-weight: 700;font-size: 13px;width:10%;">Quantity</td> 
             <td style="font-weight: 700;font-size: 13px;width:15%;">Unit Price (<img src="http://i.stack.imgur.com/nGbfO.png" width="8" height="10">)</td> 
             <td style="font-weight: 700;font-size: 13px;width:15%" colspan="2">Total Price (<img src="http://i.stack.imgur.com/nGbfO.png" width="8" height="10">)</td> 
            </tr> 
            <?php 
            $cnt = 1; 
            foreach ($product_invoice as $key => $value) { 
             ?> <tr <?php 
             if (count($product_invoice) < 9) { 
              echo 'class'; 
             } else { 
              echo 'class="product_invoice"'; 
             } 
             ?>> 
              <td 
               <?php if (count($product_invoice) == 1) { ?> style="height:650px;"<?php } ?> 
               <?php if (count($product_invoice) == 2 && ($key == (count($product_invoice)) - 1)) { ?> style="height:590px;"<?php } ?> 
               <?php if (count($product_invoice) == 3 && ($key == (count($product_invoice)) - 1)) { ?> style="height:180px;"<?php } ?> 
               <?php if (count($product_invoice) == 4 && ($key == (count($product_invoice)) - 1)) { ?> style="height:160px;"<?php } ?> 
               <?php if (count($product_invoice) == 5 && ($key == (count($product_invoice)) - 1)) { ?> style="height:110px;"<?php } ?> 
               <?php if (count($product_invoice) == 6 && ($key == (count($product_invoice)) - 1)) { ?> style="height:50px;"<?php } ?> 
               <?php if (count($product_invoice) == 7 && ($key == (count($product_invoice)) - 1)) { ?> style="height:0px;"<?php } ?> 
               <?php if (count($product_invoice) == 8 && ($key == (count($product_invoice)) - 1)) { ?> style="height:0px;"<?php } ?> 
               <?php if (count($product_invoice) == 9 && ($key == (count($product_invoice)) - 1)) { ?> style="height:0px;"<?php } ?> 
               <?php if (count($product_invoice) == 10 && ($key == (count($product_invoice)) - 1)) { ?> style="height:0px;"<?php } ?>> 
               <?php echo $cnt++; ?></td> 
              <td><?php echo $value['software_id']; ?></td> 
              <td><?php echo $value['description']; ?></td> 
              <td><?php echo $value['qty']; ?></td> 
              <td colspan="2"><?php echo $value['unit_price']; ?></td> 
              <td><?php echo $value['total_price']; ?></td> 
             </tr> 
            <?php } ?> 



           </tbody> 
          </table> 

          <table width="100%" class="table goods-table" style="margin-bottom: 0; font-size: 13px; padding: 15px 5px;  "> 
           <tbody> 
            <tr> 
             <td colspan="2" rowspan="6" style="font-weight: 700;width:70%; padding: 10px 15px;"> 


              <span style="font-weight:700;">Comments: </span> 
             </td> 
             <td style="width:15%;height:10px;">Sub Total</td> 
             <td style="width:25%;height:10px;" colspan="2"><img src="http://i.stack.imgur.com/nGbfO.png" width="8" height="10"> <?php echo $invoice['sub_total']; ?></td> 
            </tr> 
            <tr> 
             <td style="height:10px;">Other</td> 
             <td style="height:10px;"colspan="2"><img src="http://i.stack.imgur.com/nGbfO.png" width="8" height="10"> <?php echo $invoice['other']; ?></td> 
            </tr> 
            <tr> 
             <td style="height:10px;">VAT</td> 
             <td style="height:10px;" colspan="2"><img src="http://i.stack.imgur.com/nGbfO.png" width="8" height="10"> <?php echo $invoice['vat']; ?></td> 

            </tr> 

            <tr > 
             <td style="font-weight: 700;height:10px;font-size: 14px;">Grand Total</td> 
             <td style="font-weight: 700;height:10px;" colspan="2"><img src="http://i.stack.imgur.com/nGbfO.png" width="8" height="10"> <?php echo $invoice['total_price']; ?></td> 
            </tr> 
            <tr> 

             <td style="height:10px;">Mode Of Payment</td> 
             <td style="height:10px;" colspan="2"><?php 
              if ($invoice['paymode_mode'] == 1) { 
               echo 'Cash'; 
              } 
              if ($invoice['paymode_mode'] == 2) { 
               echo 'Cheque'; 
              } 
              if ($invoice['paymode_mode'] == 3) { 
               echo 'Cash and Cheque'; 
              } 
              ?></td> 
            </tr> 
            <tr> 
             <td colspan="3" >In Words: <?php echo ucwords(convert_number_to_words($invoice['total_price'])); ?> Rupees Only</td> 
            </tr> 
            <tr> 
             <td colspan="2">Installation Done<br> 
              <br><br><br> 
              Receiver's Signature with Seal 
             </td> 
             <td style="text-align: center;" colspan="3"><span style="font-weight: 700;font-size: 14px;">For </span><span style="font-weight: 700;font-size: 14px;">oft</span> 
              <?php if ($seg == "preview") { 
               ?> 
               <img src="<?php echo IMAGE_PATH_BACKEND; ?>test.png" style="margin: 0 auto;display: block;" class="text-center" alt="logo"/>  
               <?php 
              } else { 
               ?> 
               <img src="http://example.com/images/backend/test.png" style="margin: 0 auto;display: block;" class="text-center" alt="logo"/>  
              <?php } ?> 
              Authorized Signatory 
             </td> 
            </tr> 

           </tbody> 
          </table> 
          <table width="100%" class="table " style="margin-bottom: 0; font-size: 13px;  border-bottom: 2px solid #000; border-left: 2px solid #000; border-right: 2px solid #000;"> 
           <tbody> 
            <tr> 
             <td style="border-right: 2px solid #000;font-weight: 700;width: 100px;">Branches</td> 
             <td style="border-right: 2px solid #000;font-weight: 700;text-align: center;width: 100px;">sddsa</td> 
             <td style="border-right: 2px solid #000;font-weight: 700;text-align: center;width: 100px;">ewew</td> 
             <td style="border-right: 2px solid #000;font-weight: 700;text-align: center;width: 132px;">ewewq</td> 
            </tr> 
            <tr> 
             <td colspan="5" style="border : 2px solid #000;text-align: center;"><span style="font-weight:700;font-size: 13px;">Note: Computer generated Invoice and requires no signature.</span><br></td> 
            </tr> 
           </tbody> 
          </table> 

         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 


</body> 

回答

0

有一个在DOMPDF一个bug(当前版本0.8.0),其中造型与汽车利润率的图像会导致它不再占用布局中的任何垂直空间。

幸运的是,你的布局是这样的,解决这个问题的工作是相当简单的。在你的图像的代码更改为以下:

<div class="text-center"> 
    <?php 
    $seg = $this->uri->segment(2); 
    if ($seg == "preview") { 
    ?> 
    <img src="http://www.example.com/images/backend/logo_pdf.png" width="380px" height="76px" alt="logo"/> 
    <?php 
    } else { 
    ?> 
    <img src="http://www.example.com/images/backend/logo_pdf.png" width="380px" height="76px" class="text-center" alt="logo"/> 
    <?php } ?> 
</div> 

另外值得注意的是:不要修改图像的显示风格。目前dompdf需要特殊的样式才能正确呈现这些样式,并且如果您更改样式(例如:display: block;),您可能会得到意想不到的结果。