Jump to content

Help with DOMpdf


ttsprez

Recommended Posts

I'm new to PHP but learning... so please bear with me. 

I have an HTML page that contains a link to a PHP file that is supposed to generate a pdf using an HTML template and MySQL data so that the customer gets a pre-prepared pdf document for download. 

I've been working on getting the code put together using NetBeans and with help from a very generous coach/angel, which has helped a lot. But I'd like to get other eyes on this for assistance in an effort to get this completed.  I believe I am 90% done, just need a more trained eye to tell me what I'm doing wrong and how to get it fixed. I have put the error messages I'm receiving in the // comments and will color them in blue text for clarity.  

Any help I can get on this would be greatly appreciated. Also, in advance, to those nay-sayers who may happen to come along,  read this and have the urge to critique without providing real help with their responses, please don't waste the time. I will not respond and if allowed, will delete it.  By posting my issue, I know I'm not just looking for answers for me, but also, providing answers to those who come after me in search of the same.    

Link to comment
Share on other sites

As Barand has hinted - the forum is of better use when one provides the problem as well as the PERTINENT code that one thinks is causing the issue.  In your post you have not provided either.

PS - I'd like my car looked at too.  Winter's coming!

Link to comment
Share on other sites

yeah, was getting to that and got sidetracked, then somehow posted the thread before I was able to add the code... think I've work out most of the problems but still getting

Parse error: syntax error, unexpected end of file in /home1/thetitl1/public_html/pdforms/TX Title App.php on line 64

here goes the code.  As for the car, I'd have to look at them...LOL  

	<?php
	//create a connection to MySQL
require 'dogs.php';
   
$servername = "x";
$username = "x";
$password = "x";   
$dbname = "x";
$conn = mysqli_connect($servername,$username,$password,$dbname);
	// Create connection
$db = new mysqli($servername, $username, $password, $database);
	// Check for errors
if($db->connect_errno){
echo $db->connect_error;
}
//query for reference_code from 'forms' table
$refcode = filter_input(INPUT_POST, 'reference_code');
	// reference the Dompdf namespace
require_once '/home1/thetitl1/public_html/pdforms/lib/dompdf/autoload.inc.php';
$dompdf = new Dompdf\Dompdf();
$options = new Options(); $options->set('isPhpEnabled','true');
	$new_form = file_get_contents("TX_Title_App.html"); 
   
$dompdf = new Dompdf($options); $dompdf->loadHtml($new_form);
	// Execute query
$query = mysqli_query($conn,("SELECT * FROM thetitl1_livesite754.form_data WHERE form_id IN SELECT id FROM thetitl1_livesite754.forms WHERE reference_code ='$refcode'"));
	//Replaces form_fields in html temp with "data"
if ($result = mysqli_query($conn, $query)) {
    while ($row = mysqli_fetch_assoc($result)) {
$new_form = str_replace($row["name"], $row["data"], $new_form);
}
	// Always check for errors
   if($db->errno){
   echo $db->error;
   }
	// (Optional) Setup the paper size and orientation
$dompdf->setPaper(‘A4’, ‘portrait’);
	// Render the HTML as PDF
$dompdf->render();
	// Output the generated PDF to Browser
$dompdf->stream();
	// Save to file
$output= $dompdf->output();
file_put_contents('TXTitleApp.pdf', $output);
   
/* free result set */
mysqli_free_result($result);
	/* close connection */
mysqli_close($conn);    
	?>
	

 

Link to comment
Share on other sites

so I put the "}" at the end...

	if ($result = mysqli_query($conn, $query)) {
    while ($row = mysqli_fetch_assoc($result)) {
$new_form = str_replace($row["name"], $row["data"], $new_form);
}
}
	

and got this:

Fatal error: Uncaught Error: Class 'Options' not found in /home1/thetitl1/public_html/pdforms/TX Title App.php:25 Stack trace: #0 {main} thrown in /home1/thetitl1/public_html/pdforms/TX Title App.php on line 25

This is line 21 to 24 and nothing on line 25:

	// reference the Dompdf namespace
require_once '/home1/thetitl1/public_html/pdforms/lib/dompdf/autoload.inc.php';
$dompdf = new Dompdf\Dompdf();
$options = new Options(); $options->set('isPhpEnabled','true');
	

Link to comment
Share on other sites

isn't that what this is:

$options = new Options(); $options->set('isPhpEnabled','true');

 

or is this what is missing:

use Dompdf\Options;

This is the snippet of code dealing with this:

	// reference the Dompdf namespace
require_once '/home1/thetitl1/public_html/pdforms/lib/dompdf/autoload.inc.php';
$dompdf = new Dompdf\Dompdf();
$options = new Dompdf\Options();
$options = new Options(options); $options->set('isPhpEnabled','true');
	$new_form = file_get_contents("TX_Title_App.html"); 
   
$dompdf = new Dompdf($options); $dompdf->loadHtml($new_form);
	

Link to comment
Share on other sites

Barand's question was asking WHERE is the code for the class you want to use???  Usually there is an include/require statement bringing in the module that contains your actual code with all of its class properties and methods.  We aren't see anything like that, just an attempt to use hence the error message telling you it is missing.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.