Part of the EllisLab Network
This thread is a discussion for the wiki article: PDF generation using dompdf
   
2 of 2
2
PDF generation using dompdf
Posted: 18 August 2011 05:33 AM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  1
Joined  08-18-2011

write_file(‘name’, $data)
How to operate this, please tell me

Profile
 
 
Posted: 18 August 2011 09:41 AM   [ Ignore ]   [ # 17 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  09-24-2010
Quant - 18 August 2011 09:33 AM

write_file(‘name’, $data)
How to operate this, please tell me

The usage of helper is clearly documented in the wiki, you can read about the file helper in the user guide. The path specified has to be writable 0777 obviously or it doesn’t work.

For any further info you’ll have to be more specific. This is one way you could do it.

$this->load->helper(array('dompdf''file'));
// page info here, db calls, etc.     
$html $this->load->view('controller/viewfile'$datatrue);
$data pdf_create($html''false); //use false as the first parameter so it doesn't stream out (cause it do popup as a download)
$this->load->helper('file'); //as documented this helper is to be loaded for the next line to work
write_file('name'$data)
Profile
 
 
Posted: 26 August 2011 12:54 AM   [ Ignore ]   [ # 18 ]  
Summer Student
Total Posts:  19
Joined  06-03-2010

Sorry to resurrect this thread, but lolmann’s problem seems very similar to mine and I haven’t been able to find a solution after trolling through the forums and google.

I’ve used the dompdf_helper.php file and can generate around 10 to 15 pdf’s before I’m given the error:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 311296 bytes) in /home/xx/ci_system/helpers/dompdf/lib/class.pdf.php(2219) : eval()‘d code on line 1476
 
Each of the individual PDFs is very small, so I’m not sure why I’m using so much memory.

So to quote the second poster, “What can I do to make the PDF creation less of a memory sucker?”

// generate performance evals
        
$i 0;
        foreach (
$evals as $eval{
            $eval[
'student_name']  $first_name " " $last_name
            
$performance_evals .= print_performance_eval($eval)
            
$this_eval print_performance_eval($eval)
            
            
$i++;
            
$pe_filename $first_name."_".$last_name."__".$i
        
$pdf_data pdf_create($this_eval''false);
        
write_file("./assets/pdf/{$pe_filename}.pdf"$pdf_data);
        

Thanks! - Rahul

Profile
 
 
Posted: 27 September 2011 08:17 PM   [ Ignore ]   [ # 19 ]  
Grad Student
Rank
Total Posts:  41
Joined  08-15-2011

did anyone have problems with < br >not working? i get all on the same line o0

Profile
 
 
Posted: 30 January 2012 09:31 AM   [ Ignore ]   [ # 20 ]  
Summer Student
Avatar
Total Posts:  5
Joined  03-18-2011
Paul Hernández - 03 May 2011 11:47 AM

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

 


Thanks for this Paul…this got me to the ‘fonts’ permissions error, and after that was fixed it now works!!!  Thanks!!

Profile
 
 
Posted: 15 February 2012 11:32 PM   [ Ignore ]   [ # 21 ]  
Summer Student
Total Posts:  16
Joined  04-14-2011

Hi there

For some reason when i try to use the dompdf helper im getting loads of errors from:

Severity: Warning

Message: DOMXPath::query(): Invalid predicate

Filename: include/stylesheet.cls.php

Line Number: 573

to

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: include/stylesheet.cls.php

Line Number: 575

to

Severity: Warning

Message: DOMXPath::query(): Invalid expression

Filename: include/stylesheet.cls.php

Line Number: 573


etc
can someone help?

Profile
 
 
Posted: 14 March 2012 11:29 AM   [ Ignore ]   [ # 22 ]  
Grad Student
Avatar
Rank
Total Posts:  31
Joined  09-08-2008
lolmann - 09 October 2010 05:09 PM

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?

The same problem… Any solution??? my PDFs are very lightweight!

 Signature 

Retro Invaders : Ungoliante blog : Glest Free Open Source RTS

Profile
 
 
Posted: 14 March 2012 12:25 PM   [ Ignore ]   [ # 23 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2537
Joined  02-19-2009

One thing you might try at the end of your loop is unsetting the pdf object after it gets written to the filesystem so it will free the memory that was used and start fresh on each loop.

 Signature 
Profile
 
 
Posted: 14 March 2012 07:44 PM   [ Ignore ]   [ # 24 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1235
Joined  05-17-2009

I am using this simple helper for my dompdf needs:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function 
pdf_create$html$filename$stream=TRUE )
{
 
// Load dompdf
 
require_once("dompdf/dompdf_config.inc.php");

 
// Create a dompdf object
 
$dompdf = new DOMPDF();

 
// Load the HTML that will be turned into a PDF
 
$dompdf->load_html($html);

 
// Create the PDF
 
$dompdf->render();

 
// If destination is the browser
 
if($stream)
 
{
  $dompdf
->stream$filename ".pdf" );
 
}

 
// If saving to the server
 
else 
 
{
  
// Get an instance of CI
  
$CI =& get_instance();

  
// Load the CI file helper
  
$CI->load->helper('file');

  
// Save the file
  
write_file("./pdfs/$filename.pdf"$dompdf->output();
 
}

Super easy.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

Profile
 
 
Posted: 16 May 2012 02:24 AM   [ Ignore ]   [ # 25 ]  
Summer Student
Total Posts:  2
Joined  01-03-2011

Dear all,
I had follow the guide in codeingiter/wiki about pdf but when i run the system it showed the file was demaged. and it can’t opened the file.
If anybody knew about this please kindly help me.
Thanks
tola

Profile
 
 
Posted: 16 May 2012 08:31 PM   [ Ignore ]   [ # 26 ]  
Summer Student
Total Posts:  12
Joined  05-04-2012

For More Information Visit link HotDeal Source Code

Profile
 
 
   
2 of 2
2