Part of the EllisLab Network
   
2 of 4
2
Plugin to generate PDFs on the fly
Posted: 18 July 2006 02:23 PM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  7
Joined  06-20-2006

This is working great for my needs. I do have one request, however. Could someone quickly explain how to save a copy of a PDF file generated with dompdf to my server so I can send it via email as an attachment?

I just need to know what to configure to set dompdf to ‘savefile’ instead of only ‘stream’. Thanks so much.

Profile
 
 
Posted: 18 July 2006 02:36 PM   [ Ignore ]   [ # 17 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6709
Joined  03-23-2006

Hmm, its been a bit since I wrote it, but it should accept an optional third argument, in this case, just set it to “false”.  So your controller will look roughly like this:

function pdf()
{
     $this
->load->plugin('to_pdf');
     
// page info here, db calls, etc.     
     
$html = $this->load->view('controller/viewfile', $data, true);
     
pdf_create($html, 'filename', false);
}

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 19 July 2006 12:36 PM   [ Ignore ]   [ # 18 ]  
Summer Student
Total Posts:  7
Joined  06-20-2006

There isn’t a third argument in the function. Is there another solution? Thanks.

Profile
 
 
Posted: 19 July 2006 01:11 PM   [ Ignore ]   [ # 19 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6709
Joined  03-23-2006

http://www.codeigniter.com/wiki/PDF_generation_using_dompdf/

Sorry ben, I had modified it for Bamboo and not put my changes back into the wiki.  I’ve modified it in the wiki.  Hopefully that will solve address your problem.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 19 July 2006 01:13 PM   [ Ignore ]   [ # 20 ]  
Summer Student
Total Posts:  7
Joined  06-20-2006

I got it. I just added a third argument like the one you alluded to:

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) {
            $output
= $dompdf->output();
            
file_put_contents($filename.".pdf", $output);
        
} else {
            $dompdf
->stream($filename.".pdf");
        
}
    }

Profile
 
 
Posted: 19 July 2006 01:49 PM   [ Ignore ]   [ # 21 ]  
Summer Student
Total Posts:  7
Joined  06-20-2006

Wonderful! I’ve gotten that part working… I can stream or write a file without any problem. The issue now is that if I put any functions or commands after the “pdf_create” function in my controller, it gives me this error message:

Warning: require_once(C:\htdocs\im_website\cisys\plugins\dompdf/include/ci_exceptions.cls.php) [function.require-once]: failed to open stream: No such file or directory in C:\htdocs\im_website\cisys\plugins\dompdf\dompdf_config.inc.php on line 194

Fatal error: require_once() [function.require]: Failed opening required ‘C:\htdocs\im_website\cisys\plugins\dompdf/include/ci_exceptions.cls.php’ (include_path=‘.;C:\php5\pear’) in C:\htdocs\im_website\cisys\plugins\dompdf\dompdf_config.inc.php on line 194

Any ideas?

Profile
 
 
Posted: 23 August 2006 05:33 AM   [ Ignore ]   [ # 22 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  328
Joined  05-29-2006

I get the same error….. any suggestion? thank you

 Signature 

CI Js_calendar plugin click

WYSIWYG with CI

Profile
 
 
Posted: 23 August 2006 05:52 AM   [ Ignore ]   [ # 23 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  328
Joined  05-29-2006

It is perhaps needed a configuration of the dompdf in win environment? Ciao

 Signature 

CI Js_calendar plugin click

WYSIWYG with CI

Profile
 
 
Posted: 22 November 2006 06:11 AM   [ Ignore ]   [ # 24 ]  
Summer Student
Total Posts:  26
Joined  09-20-2006

EDIT: solved by updating PHP to the latest version

With dompdf I’m getting an error on which I can’t find much additional info. I know it’s a longshot, but perhaps someone around here can help me with this problem.

Warning: domdocument::domdocument() expects at least 1 parameter, 0 given in dompdf.cls.php on line 165

Fatal error: Call to undefined method domdocument::loadHTML() in dompdf.cls.php on line 284

I thought I missed the appropriate .DLL, but phpinfo() says this:

dom
DOM/XML enabled
DOM/XML API Version 20031129
libxml Version 2.6.11
HTML Support enabled
XPath Support enabled
XPointer Support enabled
Schema Support enabled
RelaxNG Support enabled

domxml
DOM/XML enabled
DOM/XML API Version 20030407
libxml Version 20611
HTML Support enabled
XPath Support enabled
XPointer Support enabled


Last but not least the piece of script I testted Dompdf with:

<?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");
?>

Profile
 
 
Posted: 26 December 2006 01:26 PM   [ Ignore ]   [ # 25 ]  
Summer Student
Total Posts:  7
Joined  07-21-2006

Hi,

I’ve problems using dompdf with codeIgniter. The problem is that all the generated pdf are corrupted and Adobe can’t read them.
I’ve followed all the instructions to get dompdf working as a plugin in codeIgniter but I doesn’t work for me.

I’m using PHP5 and Dom extension is enabled.

Could anyone help me?

Thanks in advance

Profile
 
 
Posted: 26 December 2006 01:29 PM   [ Ignore ]   [ # 26 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6709
Joined  03-23-2006

Does dompdf work for you outside of Code Igniter?  Maybe that’d be the best place for you to start…

Oh yeah, and welcome to Code Igniter wink

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 26 December 2006 01:41 PM   [ Ignore ]   [ # 27 ]  
Summer Student
Total Posts:  7
Joined  07-21-2006

Thanks for your reply Derek,

Yes, outside Code Ingniter it works well and there is not any problem.

My plugin looks like:

<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
function pdf_create($html, $filename)
{
require_once(“dompdf/dompdf_config.inc.php”);

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($filename.“.pdf”);
}
?>

And I call this function inside a my controller as:


function pdf(){
      $this->load->plugin(‘to_pdf’);
      $html=‘<html><body>‘.‘<p>kk</p>‘.‘</body></html>‘;
      pdf_create($html,‘test’);
}

And…I get alway a corrupted pdf. I don’t know why

Profile
 
 
Posted: 30 January 2007 07:07 AM   [ Ignore ]   [ # 28 ]  
Summer Student
Avatar
Total Posts:  15
Joined  09-27-2006

hi

i got also a problem with dompf and the various browsers: in IE7 it works well (the pdf is opened in the browser), in opera the generated pdf is downloaded (also ok), but in FF2.0 the page hangs up. in the title bar there’s written the controller name and (application/pdf-Object), but the pdf is never loaded

any suggestions?

this is my code:

to_pdf_pi.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");
    
}
}
?>

createpdf.php controller

function index()
    
{    
        $this
->load->plugin('to_pdf');
         
$html = $this->load->view('viewfile', $data, true);
         
pdf_create($html, 'filename');
    
}

Profile
 
 
Posted: 30 January 2007 07:23 AM   [ Ignore ]   [ # 29 ]  
Summer Student
Avatar
Total Posts:  15
Joined  09-27-2006

don’t ask me why, but it works now. could an empty variable in the controller (which is added to the filename and passed to the view) cause this misbehaviour?

Profile
 
 
Posted: 30 January 2007 09:07 AM   [ Ignore ]   [ # 30 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6709
Joined  03-23-2006

Gee, I don’t know why you would have experienced that… but sounds like its working now.  Good.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
   
2 of 4
2
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64425 Total Logged-in Users: 21
Total Topics: 80855 Total Anonymous Users: 1
Total Replies: 435214 Total Guests: 252
Total Posts: 516069    
Members ( View Memberlist )