Dompdf Error: "The Row #4 could not be found" when converting PHP file to PDF

dompdf example
dompdf->set_option('ishtml5parserenabled', true)
dompdf not rendering html
dompdf for yii2
dompdf enable html5 parser
dompdf creator
dompdf laravel
symfony dompdf

I am trying to generate a dynamic PDF out of a PHP page and it gives me this error:

Fatal error: Uncaught exception 'Dompdf\Exception' with message 'The row #4 could not be found, please file an issue in the tracker with the HTML code' in C:\xampp\htdocs\Gokujou\dompdf\src\Cellmap.php:417 Stack trace: #0 C:\xampp\htdocs\Gokujou\dompdf\src\FrameReflower\TableRow.php(62): Dompdf\Cellmap->get_frame_height(Object(Dompdf\FrameDecorator\TableRow))  #1 C:\xampp\htdocs\Gokujou\dompdf\src\FrameDecorator\AbstractFrameDecorator.php(893): Dompdf\FrameReflower\TableRow->reflow(NULL) #2 C:\xampp\htdocs\Gokujou\dompdf\src\FrameReflower\TableRowGroup.php(51): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow() #3 C:\xampp\htdocs\Gokujou\dompdf\src\FrameDecorator\AbstractFrameDecorator.php(893): Dompdf\FrameReflower\TableRowGroup->reflow(NULL) #4 C:\xampp\htdocs\Gokujou\dompdf\src\FrameReflower\Table.php(488): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow() #5 C:\xampp\htdocs\Gokujou\dompdf\src\FrameDecorator\AbstractFrameDecorator.php(893): Dompdf\FrameReflower\Table->reflow(Object(Dompdf\FrameDecorator\Block)) in C:\xampp\htdocs\Gokujou\dompdf\src\Cellmap.php on line 417

I have a button where it presses "checkout", which would generate a PDF page:

<?php
    require_once 'dompdf/autoload.inc.php';
    use Dompdf\Dompdf;

    $dompdf = new Dompdf();
    $dompdf->loadHTML(file_get_contents('receipt.php'));
    $dompdf->setPaper('A4', 'landscape');
    $dompdf->render();
    $dompdf->stream('samplepdf1');
?>

The receipt.php file is:

<?php
    include 'config.php';
?>

<!DOCTYPE html>
<html>
<head>
    <title>Gokujou Japanese Restaurant</title>
    <link rel="stylesheet" type="text/css" href="CSS/receipt.css">
</head>
<body>
    <div class="receiptContainer">
        <center>
            <img src="Images/logo.png" width="175px">
            <h4>GOKUJOU JAPANESE RESTAURANT</h4>
            <p>Total Gas Station, Hibbard Ave., Looc,<br>Dumaguete City, 6200 Negros Oriental, Philippines <br>
            09985555175 | 422-1435 <br>
            <?php echo date("Y-m-d h:i:sA"); ?>
            </p>

            <table width="90%" style="text-align: center;">
                <tr>
                    <th>DESCRIPTION</th>
                    <th>QTY</th>
                    <th>PRICE</th>
                    <th>TOTAL</th>
                </tr>
                <tr>
                    <td></td>
                </tr>
                <?php
                    $query = mysqli_query($con, "SELECT * FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = 'Checked Out'");
                    while($row = mysqli_fetch_row($query)){
                ?>
                <tr>
                    <td><?php echo $row[3]; ?></td>
                    <td><?php echo $row[5]; ?></td>
                    <td><?php echo $row[4]; ?></td>
                    <td><?php echo $row[6]; ?></td>
                </tr>
                <?php
                    }
                    $total = mysqli_query($con, "SELECT SUM(total) AS grandTotal FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = 'Checked Out' GROUP BY customerID");
                    $row = mysqli_fetch_row($total);
                    $sum = $row[0];
                ?>
                <tr>
                    <!-- break space -->
                    <tr></tr><tr></tr><tr></tr><tr></tr>
                    <tr></tr><tr></tr><tr></tr><tr></tr>
                    <tr></tr><tr></tr><tr></tr><tr></tr>

                    <td colspan="1" style="text-align: left">GRAND TOTAL: <?php echo $sum; ?></td>
                    <td colspan="3"></td>
                </tr>
                <tr style="text-align: left">
                    <td colspan="1">CASH: <?php echo $_SESSION['cash']; ?></td>
                    <td colspan="3"></td>
                </tr>
                <tr style="text-align: left">
                    <td colspan="1">CHANGE: <?php echo $_SESSION['cash'] - $sum; ?></td>
                    <td colspan="3"></td>
                </tr>
            </table>
        </center>
    </div>  <!-- fullContainer -->
</body>
</html>

It works when I just put a string in the loadHTML() statement, but it returns an error when I put a PHP file or even a static HTML, but static HTML would return row #3 instead of #4.

After much testing, I came to the conclusion that DOMPDF really dislikes empty <tr> tags.

Example:

<tr></tr><tr></tr><tr></tr><tr></tr>
<tr></tr><tr></tr><tr></tr><tr></tr>
<tr></tr><tr></tr><tr></tr><tr></tr>

My code had some of these things too (for prototyping a POC) and when I removed them I got the table to render correctly.

(I am guessing DomPDF chokes when it can't calculate the dimensions of the empty <tr> tags).

cannot open pdf file generated using dompdf, yes this is an problem of dompdf. But I am able to overcome from this problem. I created a function for pdf creation. check below function:- dompdf is not able to generate a pdf from a page of my website. However, I've saved the page and uploaded it as simple static html file, and it worked! So, I don't know if the issue is with the ur

The row #1 could not be found, please file an issue in the tracker with the HTML code..

The HTML error was that i had:

<table>
   <tr>Random text here</tr>
</table>

What fixed it is:

<table>
   <tr><td>Random text here</td></tr>
</table>

Issues · dompdf/dompdf · GitHub, Multiple images in any element (div, table, span) move outside of the container bug layout. #2180 opened 3 days ago by simonschaufi dompdf-next. After struggling to get Dompdf to respond to CSS, inline, or external styles to set the width of an image I did some Googling. Apparently this is a common issue. What did work for me was using max-width: instead of the good 'ol width:. If you're having this same issue and are unable to get Dompdf to resize your image, try this out. 2.

You have a <tr> tag inside another one:

<tr>
    <!-- break space -->
    <tr></tr><tr></tr><tr></tr><tr></tr>
    <tr></tr><tr></tr><tr></tr><tr></tr>
    <tr></tr><tr></tr><tr></tr><tr></tr>

    <td colspan="1" style="text-align: left">GRAND TOTAL: <?php echo $sum; ?></td>
    <td colspan="3"></td>
</tr>

DOMpdf -failed to load PDF document on server · Issue #1855 , DOMpdf 0.8.2 with php version 7.1 works on localhost not working on server while downloading a pdf document. Showing error forbidden and  Your HTML structure needs some work. dompdf can be finicky and a bad HTML structure can cause unexpected issues. Try running your HTML through a validator. You might also enable the HTML5 Parser (which can help correct some structural issues) by calling $dompdf->set_option ('isHtml5ParserEnabled', true); before you render the document.

HTTP Error 500 · Issue #332 · barryvdh/laravel-dompdf · GitHub, I just wanted to test everything, so passing a simple view with no variables: `​public function pdf($invoice) { $pdf = PDF::loadView('pages.home')  Dompdf. Dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) a CSS 2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements.

Errors and warnings with dompdf while pdf creating with URL , But instead of PDF both url giving something getting wrong. Please guide me. code code <?php require_once("dompdf/dompdf_config.inc.php");  Because the dompdf_config.inc.php file has been removed from this release (and is no longer referenced) all dompdf options will have to be set at run time. To simplify your in-code instantiation you can implement an intermediary script to instantiate dompdf and set the options, referencing this intermediate script in your project.

DOMPDF generation error, My colleague found the problem. It had something to do with localization. We have changed %f in sprintf to %F for localization independent floating point  Utility scripts for use with the dompdf library PHP LGPL-2.1 126 24 4 2 Updated Apr 1, 2020. dompdf.github.com dompdf project page CSS 7 3 1 0 Updated Mar 6, 2020.

Comments
  • Be careful inserting bare HTML tags into the body of questions and answers. For the most part they're automatically stripped by the system. You must mark them as code to get them to display.