using DOMPDF to export in pdf

Request for general support related to Logic Invoice.
Post Reply
manisware
Posts: 3
Joined: Thu Mar 30, 2017 3:59 am

using DOMPDF to export in pdf

Post by manisware » Fri Mar 31, 2017 2:06 am

Hi team ,

i am working with integrating dompdf library to generate pdf files,

So here's how to implement it in your own project.

Get a copy from https://github.com/dompdf/dompdf

Uncompress it. You'll get a folder (I renamed it "dompdf"), and put the whole thing into your plugins folder, ie: /system/helpers/dompdf

Create the plugin. I've named it "dompdf_helper.php"

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf");
} else {
return $dompdf->output();
}
}
?>
use it in your controllers like this
<?php
function pdf()
{
$this->load->helper(array('dompdf', 'file'));
// page info here, db calls, etc.
$html = $this->load->view('controller/viewfile', $data, true);
pdf_create($html, 'filename');
or
$data = pdf_create($html, '', false);
write_file('name', $data);
//if you want to write it to disk and/or send it as an attachment
}
?>
A few notes:

It is PHP 5 only. Sorry, I know that goes against what CI is doing here... but the level of support for CSS in the other projects wasn't acceptable for my app
You might find that there is limited or no support for a specific CSS style you want (ie: floating) and you'll need to work around with old-school tables. Ugh ..... Sorry for that...
I in no way can claim credit for writing this fine code. dompdf was released under an lgpl license, and you'll obviously need to respect that in your apps if you choose to use it.
Based on my forum post at http://www.codeigniter.com/forums/viewthread/45118/

*Another small note:

$this->load->helper('file');
needed if you use write_file()

--------------------------------------------------------
i am getting the error "404 Page Not Found
The page you are looking for cannot be found."


its not accessing the files, can anyone help me how to configure

User avatar
Esmond
Site Admin
Posts: 250
Joined: Tue Sep 15, 2015 3:08 pm
Location: Singapore
Contact:

Re: using DOMPDF to export in pdf

Post by Esmond » Tue Apr 04, 2017 8:39 pm

Is your aim to generate PDF invoices? If so, you will need to modify the invoice generating controller directly.

manisware
Posts: 3
Joined: Thu Mar 30, 2017 3:59 am

Re: using DOMPDF to export in pdf

Post by manisware » Mon May 01, 2017 9:55 pm

please let me know how to do that ?

User avatar
Esmond
Site Admin
Posts: 250
Joined: Tue Sep 15, 2015 3:08 pm
Location: Singapore
Contact:

Re: using DOMPDF to export in pdf

Post by Esmond » Tue May 02, 2017 8:32 am

It's not an easy task, it is best you hire a developer to handle it for you.

The easiest way to achieve it is to modify the controller file to include the PDF generating function.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest