PHP Mpdf-如果表格不适合实际页面,则将其移至下一页

时间:2019-11-19 10:36:09

标签: php mpdf

我必须使用Mpdf动态创建PDF文件。页面包含多个表。

如果表格不适合该页面,我想将其移至下一页。目前,它分为两部分(一页一页,请检查我添加的图像)。

是否可以将表格移至下一页?就像我说的那样,我是动态创建文件的,所以我不知道我有多少张表,或者表的最后一行(带有文本)将是多长时间。

[![最后,它分成2个部分] [1]] [1]

这是一个表格示例:

 body {
      font-family: Arial;
      line-height:12px;
      color: #000000;
      font-size:10px;
    }
    p{
      margin: 0 0 10px;
    }
    h1 {
      text-transform: uppercase;
      font-size: 16px;
      font-weight: bold;
      margin-bottom:15px;
    }
    .nabidka-container {
      width:1000px;
      margin: 0 auto;
    }

    .nabidka-container .products:first-child {
      margin-bottom:40px;
    }

    .nabidka-container .products{
      border-collapse: collapse;
      margin: 35px 0 40px 0;
      table-layout: fixed;
      width: 100%;
      overflow:wrap;
      display:block;
      page-break-inside:auto
    }
    .nabidka-container .products,.nabidka-container .products tr td, .nabidka-container .products tr th {
      page-break-inside: initial !important;
    }
    .nabidka-container .products td {
      width:25%;
      border: 1px solid gray;
      padding:2px;
      text-align: center;

    }
    .nabidka-container .products td.foto {
      border: 0px;
    }
    .nabidka-container .products td.bezramu {
      border: 0px;
      background-color: #ffffff;
    }
    .nabidka-container .products .tab_popis {
      width: 200px;
    }
    .nabidka-container .products .tab_hodnoty {
      width: 50px;
    }
    .nabidka-container .products .bold {
      font-weight: bold;
    }
    .nabidka-container .products .italic {
      font-style: italic;
    }
    .nabidka-container .products .left {
      text-align: left;
    }
    .nabidka-container .products .right {
      text-align: right;
    }
    .nabidka-container .products .price {
      background-color: #cecece;
      font-weight: bold;
    }
<div class="nabidka-container">
<table class="products" style="width:100%">
  <tbody>
  <tr>
    <td class="tab_popis foto">&nbsp;</td>
    <td class="tab_hodnoty foto"><img src="https://devlocal.optimtop.cz/storage/files/sources/images/products/p283_01_small.jpg" class="foto"></td>
    <td class="tab_hodnoty foto"><img src="https://devlocal.optimtop.cz/storage/files/sources/images/products/p213_01_small.jpg" class="foto"></td>
    <td class="tab_hodnoty foto"><img src="https://devlocal.optimtop.cz/storage/files/sources/images/products/p275_01_small.jpg" class="foto"></td>
    <td class="tab_hodnoty foto"><img src="https://devlocal.optimtop.cz/storage/files/sources/images/products/p188_01_small.jpg" class="foto"></td>
  </tr>
  <tr>
    <td class="tab_popis foto">&nbsp;</td>
    <td class="tab_hodnoty bold">Válcové brikety</td>
    <td class="tab_hodnoty bold">Brikety RUF</td>
    <td class="tab_hodnoty bold">Brikety RUF</td>
    <td class="tab_hodnoty bold">Noční brikety</td>
  </tr>
  <tr>
    <td class="tab_popis left">Kód</td>
    <td class="tab_hodnoty">DBVMPR800</td>
    <td class="tab_hodnoty">RUFHEX840</td>
    <td class="tab_hodnoty">RUFMEX840</td>
    <td class="tab_hodnoty">NOCVB720</td>
  </tr>
  <tr>
    <td class="tab_popis left">Hmotnost balení</td>
    <td class="tab_hodnoty">10 kg</td>
    <td class="tab_hodnoty">10 kg</td>
    <td class="tab_hodnoty">10 kg</td>
    <td class="tab_hodnoty">10 kg</td>
  </tr>
  <tr>
    <td class="tab_popis left">Hmotnost palety</td>
    <td class="tab_hodnoty">800 kg</td>
    <td class="tab_hodnoty">840 kg</td>
    <td class="tab_hodnoty">840 kg</td>
    <td class="tab_hodnoty">720 kg</td>
  </tr>
  <tr>
    <td class="tab_popis left">Počet balení na pal.</td>
    <td class="tab_hodnoty">80</td>
    <td class="tab_hodnoty">84</td>
    <td class="tab_hodnoty">84</td>
    <td class="tab_hodnoty">72</td>
  </tr>
  <tr>
    <td class="tab_popis left">Průměrná výhřevnost</td>
    <td class="tab_hodnoty">18.8 MJ/kg</td>
    <td class="tab_hodnoty">18.5 MJ/kg</td>
    <td class="tab_hodnoty">18 MJ/kg</td>
    <td class="tab_hodnoty">18 MJ/kg</td>
  </tr>
  <tr>
    <td class="tab_popis left price">Cena/ks</td>
    <td class="tab_hodnoty price">41.88 Kč</td>
    <td class="tab_hodnoty price">46.43 Kč</td>
    <td class="tab_hodnoty price">40.48 Kč</td>
    <td class="tab_hodnoty price">53.47 Kč</td>
  </tr>
  <tr>
    <td class="tab_popis left price">Cena/paleta</td>
    <td class="tab_hodnoty price">3350 Kč</td>
    <td class="tab_hodnoty price">3900 Kč</td>
    <td class="tab_hodnoty price">3400 Kč</td>
    <td class="tab_hodnoty price">3850 Kč</td>
  </tr>
  <tr>
    <td class="tab_popis left price">Cena/tuna</td>
    <td class="tab_hodnoty price">4188 Kč</td>
    <td class="tab_hodnoty price">4643 Kč </td>
    <td class="tab_hodnoty price">4048 Kč</td>
    <td class="tab_hodnoty price">5347 Kč</td>
  </tr>
  <tr>
    <td class="tab_popis bezramu"></td>
    <td class="tab_hodnoty italic ">SUPER CENA  průměr 9 mm</td>
    <td class="tab_hodnoty italic ">100% buk</td>
    <td class="tab_hodnoty italic ">SUPER CENA  dub,buk,jasan</td>
    <td class="tab_hodnoty italic ">dlouhá doba žhnutí</td>
  </tr>
  </tbody>
</table>
</div>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我设法使用page-break-inside: avoid对其进行了修复。但是您需要将$mpdf->shrink_tables_to_fit = 1;添加到您的mpdf对象中,或者将属性autosize="1"添加到表格元素中。 (没有 shirt_tables_to_fit autosize ,它将在一张页面中添加一张表格(至少在我的情况下是这样)。

有关表格收缩检查的更多信息,Tables - Tables - mPDF Manual