DOMPDF + Codeigniter, library upgraded, but now not working - codeigniter

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.

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...

\PhpOffice\PhpWord issue converting HTML to DOCX

Thank you in advance
i want to convert HTML into DOCX so i used \PhpOffice\PhpWord library in laravel
The code for the same is as below
$html = "<html><body><h1>HELLO DEMO</h1></body></html>";
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$phpWord->save(public_path('temp/demo.docx'), 'Word2007');
instead of saving the docx, it is showing the HTML on the webpage.
I want to save into a folder
is there anything missed by me, i used this in laravel so require_once "vendor/autoload.php"; might not be required?
You need the
require_once 'vendor/autoload.php';
also add and change
$path = public_path('temp/demo.docx');
$phpWord->save($path, 'Word2007');

DomPDF setting landscape orientation

I am having trouble setting DOMPDF to use landscape orientation. Could anyone shed some light on my problem in the code below?
function delivary_voucher($arr = null, $orientation = 'landscape') {
$this->load->library('dompdf_gen');
$this->load->library('email');
$this->load->model('Emailtemplatemodel');
I am having the same problem. After searching a lot I have finally understood how to solve the issue. I am answering this just after my coding. Hope it could help you and also for a reference of SO.
Here is how I solve the problem:
I am using dompdf as a helper, so I put the folder dompdf into system>helpers folder.
Then I have created a helper file named dompdf_helper.php into the same folder containing the following code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function get_pdf($html, $paper_size='a4', $orientation='portrait', $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
// THE FOLLOWING LINE OF CODE IS YOUR CONCERN
$dompdf->set_paper($paper_size, $orientation);
$dompdf->render();
// added by Siddiqui Noor on 29 Nov, 15
if( !empty($filename) && $stream ) {
$dompdf->stream($filename.".pdf"); // to Download PDF
} else if ($stream) {
$dompdf->stream($filename.".pdf",array('Attachment'=>0));// to open in a window
} else {
return $dompdf->output();
}
}
?>
My system folder looks like the this
Finally I call the get_pdf function in my controller like:
$data = 'Your result set goes here';
$this->load->helper(array('dompdf', 'file'));
$html = $this->load->view($view, $data, true);
get_pdf($html,'a4', 'landscape');
Happy coding as code is poetry :)

Dompdf generated pdf is 0 bytes

I am trying to save a pdf to disk.
I am using Dompdf and Codeigniter as below:
$this->load->helper('dompdf','file');
$this->load->helper('file');
$saveTo = './labels';
$data['id'] = $this -> uri -> segment(3);
$data['no_of_prints'] = $this -> uri -> segment(4);
$labelname = "Label". $data['id'] ."-". $data['no_of_prints'] . ".pdf";
$html = $this->load->view('label_view', $data, TRUE);
file_put_contents($saveTo."/".$labelname, pdf_create($html, $labelname));
While the labelname gets generated correctly. The file saved to disk reads 0 bytes and as expected I get an Adobe Reader cannot open this file ... error.
I am also using fancybox 2.0 to popup the pdf and when I right click on the popup,(the pdf does not show, i'm guessing pdf plugin issues) I am able to Save as a readable pdf that is not 0 bytes.
It is important for the application to save pdf to disk automatically. How do i save a readable pdf to disk?
I have found some old CI code (pre version 2) that used DomPDF, I had an extra parameter to write as a file.
Is this much different from yours?
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=FALSE, $orientation='portrait')
{
require_once("dompdf/dompdf_config.inc.php");
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();
$dompdf->set_paper( array(0,0, 2.175 * 72, 3.375 * 72), "landscape" ); // credit card size
$dompdf->load_html($html);
$dompdf->render();
if ($stream)
{
$dompdf->stream($filename.".pdf");
}
else
{
$CI =& get_instance();
$CI->load->helper('file');
write_file("./uploads/$filename.pdf", $dompdf->output());
}
}
?>

Resources