1
votes

i'm getting the following error in my code while converting to pdf

there's no inline block statement included and width is defined for every table header still issue is persistent

<?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();
}
}
?>

i expect to get a pdf but instead i get this error

Fatal error: Uncaught exception 'Dompdf\Exception' with message 'Min/max width is undefined for table rows' in /Applications/XAMPP/xamppfiles/htdocs/NTPC/dompdf/src/FrameReflower/TableRow.php:72 Stack trace: #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 on line 72

2
Which dompdf version are you using?digijay
@digijay i'm using an older version 0.8.2, but i also tried with the current stable version 0.8.3 but i get exact same resultszetastreak
in "pdf.php" file i removed the line containing autoload.in.php as it's no longer available in new library. then i get the error "Class 'Dompdf\Dompdf' not found"zetastreak

2 Answers

2
votes

It seems that including dompdf like you do is no longer supported, see issue 1153. The guy who's asking gets exactly the same error messages as you do.

I'd recommend to follow the dompdf installation manual and install it with composer (as it is imo thyoue most hassle-free way in the long term). I've also found something on installing composer on XAMPP, but I can't really help with this since I don't know XAMPP. As a fallback you could download a pre-configured package (described some lines below).

And also cheack the quick start tutorial to see if dompdf genereally works instead of using your own code first, because some of it might be deprecated.

Hope this helps, good luck!

0
votes

Do not apply display property to your table (not in inline styles or external styles).

Found from web:

In this case, the fix ended up being pretty simple, it didn’t like the inline style display:block; that I had added to the table. Upon a little more testing, I found that it would allow for display:inline; or display:inline-block;.

This makes sense as a table has natively the property display:table; and I think block is probably not really valid (although works fine in browsers, is a neat trick to apply to td elements to create a responsive table, and didn’t generate any warnings during validation.