php - DomPDF 中的整页 3 列布局

标签 php pdf pdf-generation dompdf

我正在使用 dompdf 生成这样的 pdf:

public function generatePdf($customerId){
    // instantiate and use the dompdf class
    $dompdf = new Dompdf();
    $options = new Options();
    $options->setIsRemoteEnabled(true);

    $dompdf->setOptions($options);
    $dompdf->loadHtml($this->renderHtml());

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

    // Render the HTML as PDF
    $dompdf->render();
    // Output the generated PDF to Browser
    $dompdf->stream();
}

$this->renderHtml() 将返回包含如下 html 文本的字符串:

       <style>
        .first-page .bottom{
          display:inline;
          width:100%;
        }
        .first-page .bottom .section{
          display: block;
          width:25%;
          height: 30px;
        }
        .first-page .bottom .left.section{
        }
        .first-page .bottom .right.section{
          width:37%;
          margin-right:0;
        }
      </style>
      <div class = "first-page">
        <div class = "bottom">
           <div class="left section">
              <p class="title">How to activate Card</p>
              <p class="main">
                <ol>
                   <li>Open Purse Pay</li>
                   <li>Lo-in to V-Card feature</li>
                   <li>Input your V-Card number.</li>
                </ol>
              </p>
           </div>
           <div class="middle section">
              <p class="title">How to use V-Card</p>
              <p class="main">
                <ol>
                   <li>Find merchant who accept V-Card payment</li>
                   <li>Stick QR-Code to Merchant Machine ‘<i>White Box</i>’ Purse Pay.</li>
                   <li>Check your transaction and credit amount from Purse Pay APP.</li>
                </ol>
              </p>
           </div>
           <div class="right section">
              <p class="title">Tips to use V-card safely</p>
              <p class="main">
                <ol>
                   <li>If you lost yout card, block your card immediately from Purse Pay App or you can contact our Customer Support <span class="bold">150 555</span>.</li>
                   <li>Keep your pin secret</li>
                   <li>Always update if you have changes on your data (Phone number, e-mail, shipping address, profile picture, etc)</li>
                   <li>If you do not use your card anymore, please shred or cut your V-Card into pieces using magenetic shredder.</li>
                   <li>Jika kartu sudah tidak lagi digunakan, harap untuk menggunting kartu V-card dengan gunting magnetik.</li>
                </ol>
              </p>
           </div>
        </div>
      </div>

结果在 pdf 中看起来像这样,div 重叠并且所有内容都向左对齐:

example

我希望结果像这样均匀分布 3 列:

example

我怎样才能做到这一点?

最佳答案

给你,你需要测试你的 css,它缺少很多东西来让它工作。 请参阅下面的代码: https://jsfiddle.net/0L25vxo8/2/

.first-page .bottom{
  display:inline;
  width:100%;
}
.first-page .bottom .section{
  display: block;
  width:32%; /* And a width for all section */
  float: left; /* Adding a floating attribute */
  height: 30px;
}
.first-page .bottom .left.section{

}
.first-page .bottom .right.section{
  width:33%; /* Overide width */
}
.first-page .bottom .middle.section{

}

关于php - DomPDF 中的整页 3 列布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56946823/

相关文章:

django - Django表单集无效

php - 使用 PHP 将值插入到可编辑的 PDF 中,并使其保持可编辑状态

php - 计算 preg_replace 正则表达式中的出现次数

php - 如何在 Javascript 中包含 PHP;谷歌图表 API

php - 使用 PHP 的 TNT Express Connect 定价模块

c# - pdfptable 中的 ItextSharp 水平对齐

iPhone PDF 创建库或函数

微软商店里的 Java

c# - 使用 iText 7 将文本环绕在单元格中的图像周围

php - 除了导航栏之外,什么会导致 WordPress 管理屏幕空白?