Error in Dompdf. It shows "class Dompdf\Dompdf" has fatal error and does not show output - dompdf

The following code in dompdf is not working.
<?php
require_once 'dompdf/dompdf_config.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$output= file_get_contents('upload.php');
$dompdf->loadHtml(html_entity_decode($output));
$dompdf->setPaper('A5', 'landscape');
$dompdf->render();
$dompdf->stream('codexworld',array('Attachment'=>0));
?>
I want the upload.php page to convert into pdf format. But, the error keeps on occuring.

Related

406 Not Acceptable An appropriate representation of the requested resource could not be found on this server

I am trying to use dompdf here to convert html to PDF, initial it works perfectly but I tried checking the link now and I got 406 Not Acceptable error. I am not sure where I got it wrong but any help will be appreciated, find below the code:
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';
$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
//$dompdf = new Dompdf();
$dompdf->loadHtml('Hello world');
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
exit(0);
And I'm using the library from this link https://github.com/nFnK/dompdf

Dompdf Class 'Dompdf\Dompdf' not found

Using Dompdf to generate a pdf file. The file is created successfully and downloads but the page I'm running it on generates a fatal error - Class 'Dompdf\Dompdf' not found.
I've downloaded the latest package and uploaded it to the server.
I'm using the quick start code from here - https://github.com/dompdf/dompdf#easy-installation
require_once 'path/to/the/folder/here/dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
I've read all the related support posts I can find but nothing seems to be working
Try this one
<?php
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
?>
This works for me. Just instantiate the dompdf class as follow: $dompdf = new \Dompdf\Dompdf();
<?php
require_once 'path/to/the/folder/here/dompdf/autoload.inc.php';
// Instantiate and use the dompdf class, as follow:
$dompdf = new \Dompdf\Dompdf();
// Then continue your code here...

how to send dynamic PDF with mail() those generate by DOMPDF library in CI?

Actually, generate the dynamic PDF successfully with the help of dompdf library in CI but not send the pdf dynamic those generated here. So tell me how to do this?
$filename = "newpdffile";
require_once APPPATH.'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml($output);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream($filename);
$file_to_save="/application/dompdf/";
$pdf=file_put_contents($file_to_save, $dompdf->output());
$this->email->from('support#aurorax.co', 'aurora exchange');
$this->email->to('masnad#aurorax.co');
$this->email->subject('pdf');
$this->email->attach($pdf);
$this->email->message('Hello!');
If you have sucesssfully generated PDF and saved in dompfdf directory
then
$pdf= 'http://yourwebsite.com/dompfdf/<?php echo $pdfNameYouGenerated; ?>';
$this->email->attach($pdf);
Use APPPATH to get the file path
$file_to_save = APPPATH. "application/dompdf/";
$pdf = file_put_contents($file_to_save, $dompdf->output());
When PDF file successfully generated and save in the directory then attach while sending email
$this->email->from('support#aurorax.co', 'aurora exchange');
$this->email->to('masnad#aurorax.co');
$this->email->subject('pdf');
$this->email->attach($pdf);
$this->email->message('Hello!');
Please check below code:
$filename = "newpdffile";
require_once APPPATH.'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml($output);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$output = $dompdf->output();
$filePath = FCPATH.'application/dompdf/filename.pdf';
file_put_contents($filePath, $output);
$this->email->from('support#aurorax.co', 'aurora exchange');
$this->email->to('masnad#aurorax.co');
$this->email->subject('pdf');
$this->email->attach($filePath);
$this->email->message('Hello!');

Trying to include template in the error 404 page

Im trying to get a error 404 page in the template which Im using, but it's not working. I have tried MY_Exceptions also.
There is view page called error404 and code goes like this:
<h1><?php echo $heading;?></h1>
<?php echo $message; ?>
Just to display error msg.
Im trying to include the below line to display error in my template, but it's throwing error:
$this->load->view("pages/template.php");
What should I do to display customized error 404 in my template using codeigniter.
It should be like this, and pass message and heading like this :
$data['heading'] = 'heading';
$data['message'] = 'your message';
$this->load->view("pages/template",$data);
instead of this
$this->load->view("pages/template.php");
Your view template.php:
<h1><?php echo $heading;?></h1>
<?php echo $message; ?>
for more :https://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view

passing the image to dompdf

I have the following code in my save.php:
<?php
require_once("dompdf/dompdf_config.inc.php");
$LgPath=$_POST['image'];
header("Content-Transfer-Encoding: binary");
header("Content-Type: image/png");
//header("Content-Disposition: attachment; filename=image.png");
$html = file_get_contents($LgPath);
//$html = readfile($LgPath); --only shows the image
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
I take succesfully using HTML2CANVAS the print screen of some element, and then i pass it to the save.php page using $POST. I want that using DOMPDF to put that image in the sample.pdf. Using this code I only have this text in the sample.pdf "‰PNG", and I have don't figure how to fix it. Using readfile i see the image, but that's it... Any suggestions? Thank you.
You're reading your image into a variable and passing it to dompdf. As such dompdf is treating that text that makes up that image as HTML source. Since your image is readable from the PHP script at the location stored in $LgPath you should be able to do something like this:
<?php
require_once("dompdf/dompdf_config.inc.php");
$LgPath=$_POST['image'];
$html = '<img src="' . $LgPath . '">';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>

Resources