【问题标题】:how to resolve min/max width error domp while generating pdf?生成pdf时如何解决最小/最大宽度错误domp?
【发布时间】:2019-05-23 21:03:02
【问题描述】:

在转换为 pdf 时,我的代码中出现以下错误

没有包含内联块语句,并且为每个表头定义了宽度仍然存在问题

<?php
//print_invoice.php
if(isset($_GET["pdf"]) && isset($_GET["id"]))
{
    require_once 'pdf.php';
    include('connection2.php');
    $output = '';
    $statement = $connect->prepare("
  SELECT * FROM POrder
  WHERE order_id = :order_id
  LIMIT 1
 ");
    $statement->execute(
    array(
        ':order_id'       =>  $_GET["id"]
    )
);
$result = $statement->fetchAll();
foreach($result as $row)
{
    $output .= '
   <table width="100%" border="1" cellpadding="5" cellspacing="0">
<tr>
 <td colspan="2" align="center" style="font-size:18px"><b>Invoice</b></td>
</tr>
<tr>
 <td colspan="2">
  <table width="100%" cellpadding="5">
   <tr>
    <td width="65%">
     To,<br />
     <b>Vendors Name</b><br />
     Name : '.$row["vendorname"].'<br />
     Description : '.$row["description"].'<br />
    </td>
    <td width="35%">
     Reverse Charge<br />
     Invoice No. : '.$row["order_no"].'<br />
     Invoice Date : '.$row["order_date"].'<br />
    </td>
   </tr>
  </table>
  <br />
  <table width="100%" border="1" cellpadding="5" cellspacing="0">
   <tr>
    <th>Sr No.</th>
    <th>Item Name</th>
    <th>Quantity</th>
    <th>Price</th>
    <th>Actual Amt.</th>
    <th colspan="2">GST (%)</th>
    <th rowspan="2">Total</th>
   </tr>
   <tr>
    <th></th>
    <th></th>
    <th></th>
    <th></th>
    <th></th>
    <th>Rate</th>
    <th>Amt.</th>
   </tr>';
    $statement = $connect->prepare(
            "SELECT * FROM POrder_item
   WHERE order_id = :order_id"
       );
        $statement->execute(
        array(
            ':order_id'       =>  $_GET["id"]
        )
    );
    $item_result = $statement->fetchAll();
    $count = 0;
    foreach($item_result as $sub_row)
    {
            $count++;
            $output .= '
   <tr>
    <td>'.$count.'</td>
    <td>'.$sub_row["item_name"].'</td>
<td>'.$sub_row["item_quantity"].'</td>
<td>'.$sub_row["item_price"].'</td>
<td>'.$sub_row["item_price_bt"].'</td>
<td>'.$sub_row["item_gst"].'</td>
<td>'.$sub_row["item_price_at"].'</td>
    <td>'.$sub_row["final_amount"].'</td>
   </tr>
   ';
        }
        $output .= '
  <tr>
   <td align="right" colspan="11"><b>Total</b></td>
   <td align="right"><b>'.$row["total_after_tax"].'</b></td>
  </tr>
  <tr>
   <td colspan="11"><b>Total Amt. Before Tax :</b></td>
   <td align="right">'.$row["total_before_tax"].'</td>
  </tr>
  <tr>
   <td colspan="11">Add : GST :</td>
   <td align="right">'.$row["gst"].'</td>
  </tr>
   <td colspan="11"><b>Total Tax Amt.  :</b></td>
   <td align="right">'.$row["order_total_tax"].'</td>
  </tr>
  <tr>
   <td colspan="11"><b>Total Amt. After Tax :</b></td>
   <td align="right">'.$row["total_after_tax"].'</td>
  </tr>

  ';
    $output .= '
      </table>
     </td>
   </tr>
   </table>
   ;
    }
    $pdf = new Pdf();
    $file_name = 'Invoice-'.$row["order_no"].'.pdf';
    $pdf->loadHtml($output);
    $pdf->render();
    $pdf->stream($file_name, array("Attachment" => false));
}
?>

// pdf.php

<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
class Pdf extends Dompdf{
public function __construct() {
parent::__construct();
}
}
?>

我希望得到一个 pdf,但我得到了这个错误

致命错误:带有消息的未捕获异常“Dompdf\Exception” '表行的最小/最大宽度未定义'在 /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameReflower/TableRow.php:72 堆栈跟踪:#0 /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(903): Dompdf\FrameReflower\TableRow->get_min_max_width() #1 /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameReflower/AbstractFrameReflower.php(268): Dompdf\FrameDecorator\AbstractFrameDecorator->get_min_max_width() #2 /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(903): Dompdf\FrameReflower\AbstractFrameReflower->get_min_max_width() #3 /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameReflower/AbstractFrameReflower.php(268): Dompdf\FrameDecorator\AbstractFrameDecorator->get_min_max_width() #4 /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(903): Dompdf\FrameReflower\AbstractFrameReflower->get_min_max_width in /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameReflower/TableRow.php 在第 72 行

【问题讨论】:

  • 您使用的是哪个 dompdf 版本?
  • @digijay 我使用的是旧版本 0.8.2,但我也尝试使用当前稳定版本 0.8.3,但我得到完全相同的结果
  • 在“pdf.php”文件中,我删除了包含 autoload.in.php 的行,因为它在新库中不再可用。然后我收到错误“找不到类'Dompdf\Dompdf'”

标签: php html web pdf-generation dompdf


【解决方案1】:

不要将 display 属性应用于您的表格(不是内联样式或外部样式)。

来自网络:

在这种情况下,修复非常简单,它不喜欢我添加到表格中的内联样式 display:block;。 经过更多测试,我发现它允许display:inline;display:inline-block;

这是有道理的,因为表格本身具有 display:table; 属性,我认为 block 可能不是真正有效的(虽然在浏览器中工作正常,但它是一个巧妙的技巧,适用于 td 元素以创建响应式表格,但没有t 在验证期间生成任何警告。

【讨论】:

  • 能否请您链接原始页面?
【解决方案2】:

似乎不再支持像你这样包含 dompdf,see issue 1153。提出问题的人会收到与您完全相同的错误消息。

我建议关注dompdf installation manual 并使用composer 安装它(因为从长远来看,这是您最省心的方式)。我还在installing composer on XAMPP 上找到了一些东西,但我真的无能为力,因为我不知道 XAMPP。作为后备方案,您可以下载预配置的包(在下面的几行中描述)。

还要检查quick start tutorial 以查看 dompdf 是否能正常工作,而不是先使用您自己的代码,因为其中一些可能已被弃用。

希望这会有所帮助,祝你好运!

【讨论】:

  • 感谢伙伴的帮助!我更新了已弃用的代码并安装了作曲家。未捕获的异常错误仍然存​​在,我使用 $dompdf->set_option('isHtml5ParserEnabled', true);因为我的 html 表格中存在一些结构错误。
  • 酷!很高兴我能帮上忙。
猜你喜欢
  • 1970-01-01
  • 2013-05-14
  • 2012-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
  • 2011-02-16
  • 1970-01-01
相关资源
最近更新 更多