Reputation: 39
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
Upvotes: 1
Views: 8573
Reputation: 555
In my situation the problem vas html syntax instead was after fixing problem solved
Upvotes: 0
Reputation: 99
For me @Ghazni Ali had the right cause. Adding any type of display to a table made this error occur.
I was trying to get my elements properly spaced and inline.
What I found was I had to add width to my table and then add additional widths to the td inside of the table.
Below is trying to get a 20% and 80% split.
<table style="width: 100%;">
<tbody>
<tr>
<td style="width: 20% !important; border: 1px solid black;">
<p >Left Test</p>
</td>
<td style="width: 80% !important; border: 1px solid black;">
<p >Right Test</p>
</td>
</tr>
</tbody>
</table>
I tried similar methods with using a div tag but it wouldn't appear correct.
The first example is with the table and the bottom two are with div tags.
Upvotes: 0
Reputation: 71
The solution that worked for me was to downgrade dompdf to 1.0.0
Am not saying it's the best solution but as for now with it was not depending on so many other packages but as it comes with phenx/php-svg-lib and phenx/php-font-lib those were also downgraded.
And also the downside of this is that it was installed in the main packages in composer.json
Note: This will upgrade, downgrade and remove packages currently locked to specific versions of the dompdf/dompdf:1.0.0
The command I used is composer require dompdf/dompdf:1.0.0 -w
Upvotes: 0
Reputation: 266
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.
Upvotes: 1
Reputation: 1366
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!
Upvotes: 2