Ashish Sood Posted February 27, 2014 Share Posted February 27, 2014 Hi all I am trying to fetch my table content into an PDF, But getting error message. Error message Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Requested HTML document contains no data.' in C:xampphtdocsprojectsampleofficedompdfincludeframe_tree.cls.php:135 Stack trace: #0 C:xampphtdocsprojectsampleofficedompdfincludedompdf.cls.php(293): Frame_Tree->build_tree() #1 C:xampphtdocsprojectsampleofficedompdfincludedompdf.cls.php(377): DOMPDF->_process_html() #2 C:xampphtdocsprojectsampleofficedom.php(236): DOMPDF->render() #3 {main} thrown in C:xampphtdocsprojectsampleofficedompdfincludeframe_tree.cls.php on line 135 my PHPscript <html><body><input type=text name=search ><span class="error"> <?php echo $error;?></span><br><input type=submit name=submit value=Search></form></body></html><?phprequire_once("dompdf/dompdf_config.inc.php"); $date=date("m/d/Y"); echo "Today Date Is = "; echo "$date"; echo "<h1><center>Midrange, Turnover For All The Accounts </center></h3>"; include("../../../../../../../inetpub/wwwroot/dbcon/connection.php"); function content(){ if(isset($_POST['submit'])) { include("../../../../../../../inetpub/wwwroot/dbcon/connection.php"); echo "<h3>Turnover For Apria</h3>"; $search=htmlspecialchars($_POST['search']); $selectcondition = "SELECT * FROM customer.order where DATE='".$search."'"; //Select Query Which check the whether the TURNOVER for the given INCIDENT is exit or not. $check=mysql_query($selectcondition,$con); $fetch=mysql_fetch_row($check); if(!$fetch) //If checklist for the given date is not exit execute if condition { echo "<font color='red'>"; echo "<br>"; echo "No records Found In The Database"; echo "<br>"; echo "</font>"; } else //if the above condition is flase ! { $sql= "select * from customer.order where DATE='".$_POST['search']."'"; $mydata=mysql_query($sql,$con); //$fetch_rows=mysql_fetch_row($mydata); echo "<table class='mytable' width='100%' height='10%' border='1' cellspacing='0'> <tr> <th>DATE</th> <th>ORDER</th> <th>SUTNAME</th> <th> COMMENTS</th> </tr>"; while($records = mysql_fetch_array($mydata)) { echo "<tr>"; echo "<td>" . $records['TIMESTAMPS'] . " </td>"; echo "<td>" . $records['ORDER']. " </td>"; echo "<td>" . $records['CUSTNAME'] . " </td>"; echo "<td align='center'>"; echo '<textarea name="textarea" cols="100" >'.$records['COMMENTS'].'</textarea><br>'; echo "</td>"; } } echo "</table>"; } $html=content(); $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("order.pdf"); ?> Please tell me what sort of changes i need to do into my current script. Thanks, Ashish Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2014 Share Posted February 27, 2014 You're trying to render the return value of the content function, but content doesn't return a value. That is exactly why the error message says the HTML contains no data. Link to comment Share on other sites More sharing options...
Ashish Sood Posted February 28, 2014 Author Share Posted February 28, 2014 (edited) I have corrected the code but now error comes in. please find the below code <?php require_once("dompdf/dompdf_config.inc.php"); function content(){ $content=""; if(isset($_POST['submit'])) { include("../../../../../../../inetpub/wwwroot/dbcon/connection.php"); $content .= "<h3>ORDER STATUS</h3>"; $search=htmlspecialchars($_POST['search']); $selectcondition = "SELECT * FROM customer.order where DATE='".$search."'"; //Select Query Which check the whether the TURNOVER for the given INCIDENT is exit or not. $check=mysql_query($selectcondition,$con); $fetch=mysql_fetch_row($check); if(!$fetch) //If checklist for the given date is not exit execute if condition { $content .= "<font color='red'>"; $content .= "<br>"; $content .= "No Order Found In The Database"; $content .= "<br>"; $content .= "</font>"; return $content; } else //if the above condition is flase ! { $sql= "select * from customer.order where DATE='".$_POST['search']."'"; $mydata=mysql_query($sql,$con); //$fetch_rows=mysql_fetch_row($mydata); $content .= "<table class='mytable' width='100%' height='10%' border='1' cellspacing='0'> <tr> <th>DATE</th> <th>ORDER</th> <th>CUSTNAME</th> <th>COMMENTS</th> </tr>"; while($records = mysql_fetch_array($mydata)) { $content .= "<tr>"; $content .= "<td>" . $records['TIMESTAMPS'] . " </td>"; $content .= "<td>" . $records['ORDER']. " </td>"; $content .= "<td>" . $records['CUSTNAME'] . " </td>"; $content .= "<td align='center'>"; $content .= '<textarea name="textarea" cols="100" >'.$records['COMMENTS'].'</textarea><br>'; $content .= "</td>"; } $content .="</table>"; return $content; } } } $html= content(); if($html){ $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("order.pdf"); }else{ echo "Look like something is wrong here ."; } ?> After making the changes, A corrupted pdf file is generated. Edited February 28, 2014 by Ashish Sood Link to comment Share on other sites More sharing options...
justsomeguy Posted February 28, 2014 Share Posted February 28, 2014 A corrupt file like that typically means that you are outputting other content, like HTML or even just whitespace (or an error message), either before or after the file. If you're generating a file then the output needs to be only that file and nothing else. If you want to check for error messages then you can either open the PDF in a text editor, or configure PHP to use error logging instead of displaying the error messages. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now