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

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

Related

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!');

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

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.

DOMPDF + Codeigniter, library upgraded, but now not working

I have been using the old version of dom pdf in codeigniter for pdf generation and recently I changed the core dompdf directory to newer version dompdf-0.5.2.zip.
Below is the code that I've been using to connect to dompdf class:
class Pdf{
var $_dompdf = NULL;
/**
* Constructor Method
**/
function __construct(){
ini_set("memory_limit", "1G");
require_once("Dompdf/dompdf_config.inc.php");
if(is_null($this->_dompdf)){
$this->_dompdf = new DOMPDF();
}
}
/**
* HTML to PDF Conversion method
**/
function convert_html_to_pdf($_html, $_filename = '', $_stream = false, $_orientation = "portrait"){
$this->_dompdf->set_paper("a4", $_orientation);
$this->_dompdf->load_html($_html);
$this->_dompdf->render();
if($_stream){
$this->_dompdf->stream($_filename);
} else{
file_put_contents($_filename, $this->_dompdf->output());
}
}
}
Now when I try to generate pdf, it gives me following error:
Fatal error: Class 'DOMPDF' not found in D:\xampp\htdocs\app\application\libraries\Pdf.php on line 21
any solution would be appreciated
Thanx
Please first try with this example. Just store this in a file under htdocs directory of your xampp or whatever server you are using.
<?php
require_once("dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
Just change the dompdf directory path as per your requirement.
I solved this myself by uploading the dompdf version to the latest version, though it is beta, all seems to work perfectly now.

DOMPDF is not producing correct output

DOMPDF is producing only html path in pdf file instead of content at html path.
include_once('dompdf/dompdf_config.inc.php');
$html= $this->load->view('view_pdf');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
If anybody have any idea please give here.
From the codeigniter docs:
Returning views as data
There is a third optional parameter lets you change the behavior of
the function so that it returns data as a string rather than sending
it to your browser. This can be useful if you want to process the data
in some way. If you set the parameter to true (boolean) it will return
data. The default behavior is false, which sends it to your browser.
Remember to assign it to a variable if you want the data returned:
$string = $this->load->view('myfile', '', true);
So your code should be:
include_once('dompdf/dompdf_config.inc.php');
$html= $this->load->view('view_pdf','',true);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
You need the content of view_pdf to load as a string into $html:
$html = $this->load->view('view_pdf', '', true);

Resources