2016-04-25 331 views
1

我正在使用MPDF生成发票。我的项目行是动态的,所以显示项目的表格的高度应该是灵活的。当我使用下面的代码打印PDF:如何在mpdf中设置表格的高度

<!-- Latest compiled and minified CSS --> 
<?php echo $this->Html->css(array('bootstrap.min','AdminLTE.min','skin-green','font-awesome.min')); ?> 
<style type="text/css"> 
    .products{ 
    width: 100%; 
    border-collapse: collapse; 
    } 
    h2,h3{ 
    margin: 0; 
    padding:0; 
    } 
    .border{ 
    border: 1px solid black; 
    padding:5px; 
    } 
    table.products{ 
    border: 1px solid black; 
    height: 500px; 
    margin-left: -6px; 
    margin-right: -6px; 
    margin-bottom: -6px; 
    } 
    .products tr td{ 
    padding:5px; 
    border:1px solid #333; 
    } 
    .products tr th{ 
    padding:5px; 
    border:1px solid #333; 
    } 
    .pull-right{ 
    float: right; 
    } 
</style> 
<!-- title row --> 
<div class="border"> 
    <table width="100%"> 
    <tr> 
     <td style="width:35%"> 

     </td> 
     <td style="width:35%" align="center"> 
     Estimate 
     </td> 
     <td style="width:35%" align="right"> 
     Date: <?php echo date('d-m-Y',strtotime($invoice['Invoice']['dated'])); ?> 
     </td> 
    </tr> 
    <tr> 
     <td colspan="3" align="center"> 
     <br> 
     <h3>Invoice Heading</h3> 

     </td>     
    </tr> 
    </table> 
    <hr/> 
    <div class="row"> 
    <div class="col-xs-12 border-right"> 
     To: <?php echo $invoice['Invoice']['user']; ?><br> 
     Mobile.: <?php echo $invoice['Invoice']['mobile']; ?><br> 
     Address: <?php echo $invoice['Invoice']['address']; ?><br> 

    </div>  
    </div> 
    <hr/> 
    <!-- Table row --> 
    <div class="row"> 
    <div class="col-xs-12 table-responsive"> 
     <table class="products"> 
     <thead> 
      <tr>    
      <th width="60"><?php echo __('Sr. No.'); ?></th> 
      <th><?php echo __('Quantity'); ?></th> 
      <th width="250"><?php echo __('Particulars'); ?></th> 
      <th><?php echo __('Rate'); ?></th> 
      <th><?php echo __('Amount'); ?></th> 
      </tr> 
     </thead> 
     <tbody> 
      <?php $i = 0; foreach ($invoice['InvoiceDetail'] as $invoiceDetail): $i++; ?> 
      <tr> 
       <td><?php echo $i; ?></td> 
       <td><?php echo $invoiceDetail['quantity']; ?></td> 
       <td><?php echo $invoiceDetail['Item']['name']; ?></td> 
       <td><?php echo $invoiceDetail['price']; ?></td> 
       <td align="right"><?php echo $invoiceDetail['amount'] ?></td> 
      </tr> 
      <?php endforeach; ?> 
      <tr> 
       <td colspan="3"></td>    
       <td>Total: </td> 
       <td align="right"><i class="fa fa-inr"></i> <?php echo number_format((float)$invoice['Invoice']['total'], 2, '.', ''); ?> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="5">Amount in words: Rs.<?php echo $c2w ?></td> 
      </tr> 
     </tbody>     
     </table> 
    </div><!-- /.col --> 
    </div><!-- /.row --> 
</div>   

它打印PDF格式如下: enter image description here

但我需要按如下方式打印:

enter image description here

我有尝试使用行高,但它扭曲的看法,因为valign在td将不会对齐内容在顶部。

随着TD打印line-height:100px看起来如下:

enter image description here

有没有办法通过动态增加项目表的高度,填补了整个页面。

回答

0

我正在寻找mpdf行高,发现这个未答复的问题。

下面是我用过的一些解决方案。

选项1

  1. 环路
  2. 估计每一行的大致高度时计数每一行。通常这是固定在一条线上,所以这不是问题。
  3. 扣减表
  4. 所需的高度在环(行×高度),如果行数等于总行那么它的最后一行在这种情况下,你可以在最后一排
添加 <td height="##">

选项2

添加填料行

  1. 图有多少行需要在发票上填写ŧ他适量(保持小于最大值)
  2. 然后使用类似下面填写完表格后

    if($current_row < $total_rows){ for($i=$current_row; $i<$total_rows; $i++){ echo '<tr><td colspan="4"></td></tr>'; } } >
-1

你需要指定它像波纹管在细胞内?

<td style="height:4.6cm; vertical-align: text-top;"></td> 
+0

失败的第二行问题。 –

0

以下是我用过的一些解决方案。 1)计数在TBODY 2所有TR)然后使用TD

0

的CSS设置的line-height据MPDF库here的文档发现,TBODY的最后一个TR,我们只能设置块级元素的高度。我面临着同样的问题,然后我把我的表格移动到一个div中,并向下面的div添加了高度。

<div height="870" style="border:solid 1px #ccc"> 
    <table class="table> 
     Your table content here... 
    </table> 
</div>