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...
Related
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
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!');
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.
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.
Using dompdf i generate pdf file. I am successfully generate it .
But after generating it when I open it in Foxit reader it's open very small size in 51.79% mode. When i select 'Fit width' or 125% it show properly.
When I open the pdf by default it open 125% mode can it be possible ?
I used following function:
function pdf_create($html, $filename)
{
ini_set("memory_limit", "50M");
//define pdf store path
$invoice_pdf_path = ABSOLUTE_PATH;
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait");
$dompdf->render();
//$dompdf->stream("abc_out.pdf");
$pdf = $dompdf->output();
#file_put_contents($invoice_pdf_path . $filename . ".pdf", $pdf);
}
With dompdf 0.6 beta you can set the default view of the PDF by adding a meta tag in your HTML source code:
<meta name="dompdf.view" content="FitH" />
Possible values are "XYZ", "Fit", "FitH", "FitV", "FitR", "FitB", "FitBH", "FitBV", described here