Part of the EllisLab Network
This thread is a discussion for the wiki article: PDF generation using dompdf
   
1 of 2
1
PDF generation using dompdf
Posted: 07 September 2010 02:28 PM   [ Ignore ]  
Summer Student
Total Posts:  6
Joined  07-16-2010

Images are rendering as Large Red X’s, but the html src path is accurate. GD is enabled. I’m running this on WAMP in WinXP.

Any thoughts?

Profile
 
 
Posted: 09 October 2010 05:09 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  22
Joined  12-03-2008

I’m creating a larger number of PDFs with dompdf and write them to a folder. In order to do this, I loop through a set of database rows and for each row I call

pdf_create($html$filenameFALSE

as described in the wiki article.

When I try to create more than 10 PDFs or so the process errors

[09-Oct-2010 19:35:52] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 1245184 bytesin /Applications/MAMP/htdocs/mydirecotry/system/plugins/dompdf/lib/class.pdf.php(2219) : eval()'d code on line 5914 

Basically it says that the PDF creation is using more than 32 MB Ram.

Each of the PDFs is only 4 KB.

I temporarily got the whole think working by putting

ini_set("memory_limit","120M")

in the beginning of the plugin function. It increases the memory limit to 120 MB. This works for creating 10 PDFs. But as soon as I want more (30 PDFs or so) the same thing happens and I have to increase the memory limit even more.

So far I’m testing the whole thing on my local machine and can put up the memory limit. But I figure that the ressources on my webspace are more limited and 120 MB seems too much.

What can I do to make the PDF creation less of a memory sucker?

Profile
 
 
Posted: 02 November 2010 07:56 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  1
Joined  11-02-2010

Closing the to_pdf_pi.php with ?> caused ‘headers already sent’ error

Profile
 
 
Posted: 13 November 2010 12:26 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  04-15-2010

More Info:
CodeIgniter Dojo Helper
SatSun Studio China

 Signature 
Profile
 
 
Posted: 17 December 2010 02:09 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  04-15-2010

How to use FusionCharts Free with CodeIgniter?
How to use FusionCharts Free with CodeIgniter?
How to use FusionCharts Free with CodeIgniter?
LINK: click Here!

 Signature 
Profile
 
 
Posted: 24 February 2011 10:49 PM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  09-24-2010

I got it working flawlessly a couple of days ago. Since plugins aren’t supported anymore, I converted it to helper, named 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->set_paper("a4""landscape" );
    
$dompdf->render();
    
$dompdf->stream($filename ".pdf");
}
?> 

I’ve put the whole dompdf library to application/helpers/dompdf folder and I call it like this from controller:

function createpdf()
    
{
    $this
->load->helper('dompdf');
    
$this->load->helper('file');
    
$data['somedata']$this->somemodel->somemethod();
    
$html $this->load->view('pdf/view'$datatrue);
    
pdf_create($html'somefilename');
    

This way I can format the view precisely the way I want. I’ve tried at least 5 pdf libraries, but this one is by far the most convenient to use.

I also want to post a link to super useful font making tool, which can help you make printouts in different charsets, for example farsi, central european… You do have to convert the data you’re passing to HTML Entity. For central european, that would mean a str_replace like this:

$in = array ('Č''č''Š''š''Ž''ž''Đ''đ''Ć''ć');
$out = array ('&#268;''&#269;''&#352;''&#353;''&#381;''&#382;''&#272;''&#273;''&#262;''&#263;');
str_replace($in$out$variable

I hope this helps someone.

Profile
 
 
Posted: 24 March 2011 08:02 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  6
Joined  10-16-2010

Thanks to djmccormick for this - it’s really easy to implement.

If you’re looking at getting dompdf working in CodeIgniter 2 check this thread out:

http://codeigniter.com/forums/viewthread/86724/

Edit: updated link to the forum thread.

 Signature 

http://about.me/mikkelz

Profile
 
 
Posted: 24 March 2011 09:02 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  09-24-2010

Errr, you linked this exact thread, must be an error.

Profile
 
 
Posted: 02 April 2011 10:12 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Avatar
Total Posts:  6
Joined  10-16-2010

Sorry guys, posted that in a rush without checking.

This is the thread that I read which helped me to get CI 2 working with dompdf: http://codeigniter.com/forums/viewthread/86724/

 Signature 

http://about.me/mikkelz

Profile
 
 
Posted: 02 May 2011 11:58 AM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  16
Joined  05-17-2010

Hi:

I tried the Coccodrillo solutions but I’m getting the same error

Fatal error: require_once() [function.require]Failed opening required '/home/pauldj54/Desktop/pdftest2/application/helpers/dompdf/include/ci_exceptions.cls.php' (include_path='.:/opt/lampp/lib/php'in /home/pauldj54/Desktop/pdftest2/application/helpers/dompdf/dompdf_config.inc.php on line 210 

[edit]: Sorry, I have not read the Coccodrillo post, so, my comment is redundant

Please, does anyone can post exactly how to use dompdf with ci2?

The explanation in the wiki http://codeigniter.com/wiki/PDF_generation_using_dompdf/ doesn’t work with ci2, or at least doesn’t align with the ci2 philosophy where plugins are no longer in use (http://philsturgeon.co.uk/news/2010/03/codeigniter-2). So, I think the best approach is try to convert the plugin in a helper or a library and place it inside the application folder.

I tried to put the create_pfd function inside the controller and other solutions but I got errors like this:

Fatal error: require_once() [function.require]Failed opening required '/home/pauldj54/Desktop/pdftest2/application/controllers/dompdf/include/ci_exceptions.cls.php' (include_path='.:/opt/lampp/lib/php'in /home/pauldj54/Desktop/pdftest2/application/controllers/dompdf/dompdf_config.inc.php on line 210 

Any comment will be appreciated

Regards

 Signature 

Paul Vicente Hernández Moreno

Profile
 
 
Posted: 03 May 2011 11:22 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  09-24-2010

From your edit, I can’t see if you managed to resolve your problems. What you posted suggests a problem with filepaths. Anyways, a while ago I posted a link to a full working pdf test on my server. It’s still there to download. The CI version is 2.0.0., but nothing has changed AFAIK. Now, if this doesn’t do it for you, you have to start reviewing your server settings.

Profile
 
 
Posted: 03 May 2011 11:47 AM   [ Ignore ]   [ # 11 ]  
Summer Student
Avatar
Total Posts:  16
Joined  05-17-2010

Thank you very much for your quick reply!

I moved the dompdf folder from one side to another and I forgot to give the right permissions to the fonts folder. The library always handle the errors in a way that fires this generic message (Failed opening required some_file.cls.php)

Let me explain it a little bit better. I had a problem with a permission to access a specific folder, which caused a codeigniter exception handle by the ci_exceptions class, and when the program run into this piece of code (file: dompdf_config_inc.php):

function DOMPDF_autoload($class{
  $filename 
mb_strtolower($class) . ".cls.php";
       require_once(
DOMPDF_INC_DIR "/$filename");
 

The file ci_execption.cls.php is tried to be included, this caused the error message I posted. I modified the code to recieved the real error message in the following way:

function DOMPDF_autoload($class{
  $filename 
mb_strtolower($class) . ".cls.php";
   if (
file_exists(DOMPDF_INC_DIR "/$filename")) {
     
require_once(DOMPDF_INC_DIR "/$filename");
   
}

And then I was able to read the real error message and that’s it, I fixed the problem.

Thanks again for your posts

 Signature 

Paul Vicente Hernández Moreno

Profile
 
 
Posted: 10 May 2011 02:51 PM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  30
Joined  03-17-2011

I need help. I am trying generate pdf, but the file is corrupted.
using CI 2.0.2, dompdf 0.6

Profile
 
 
Posted: 11 May 2011 06:18 AM   [ Ignore ]   [ # 13 ]  
Summer Student
Avatar
Total Posts:  16
Joined  05-17-2010

Can you give more details?
Which file is corrupted?
What is the error message?
I strongly suggest you to use xdebug (a PHP debuger), it helps me a lot when a 3rd party library gives me an error during the installation.

 Signature 

Paul Vicente Hernández Moreno

Profile
 
 
Posted: 11 May 2011 06:46 AM   [ Ignore ]   [ # 14 ]  
Summer Student
Total Posts:  30
Joined  03-17-2011

I dont have error message… simply pdf is generated… but dont open.

Now.. I am trying to use mpdf .. pdf is generated OK, but some user cannot open it. They receive “font error” in pdf reader.

Profile
 
 
Posted: 09 June 2011 12:15 PM   [ Ignore ]   [ # 15 ]  
Summer Student
Total Posts:  17
Joined  08-27-2010

Anyone having any luck getting images to load? Everything I do seems to generate a red X.

EDIT: The answer is to use the physical server path to your image within the image tags. Bizarre, but it will work.

Profile
 
 
   
1 of 2
1