CodeIgniter Forums
Dompdf not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Dompdf not working (/showthread.php?tid=27416)



Dompdf not working - El Forum - 02-10-2010

[eluser]bhakti.thakkar[/eluser]
Hello all,

there is a button on my page for creating a preview. when the user clicks the button, there is a prompt to either Open or Save the document. When a user clicks Save and then open the Saved document, it works well. But if directly clicks on open, then it generates :
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined index: dompdfuniqueid</p>
<p>Filename: include/frame.cls.php</p>
<p>Line Number: 183</p>

</div>%PDF-1.3
%âãÏÓ

1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
/OpenAction 8 0 R >>
endobj
2 0 obj

ETC ETC

to_pdf_pi.php

Code:
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 {

         $output = $dompdf->output();
         file_put_contents('../../tmp/pdf/'.$filename.".pdf", $output);
//        write_file("./tmp/pdf/$filename.pdf", $dompdf->output());
    }
}


Controller : certificate.php
Code:
function PreviewCertificatePDF($TransactionCertificate_ID , $ITCType_TI) {
        
        $this->load->plugin('to_pdf');
        $data['TransactionCertificate_ID'] = $TransactionCertificate_ID;
        $query = $this->db->query("Exec up_parmsel_rpt_TempTransactionCertificate @TransactionCertificate_ID='$TransactionCertificate_ID' , @Company_ID='' ");
@TransactionCertificate_ID='$TransactionCertificate_ID' , @Company_ID='' ");
        $data['pgdata'] =$query->result_array();
    
             $pg="PreviewCertificate";
    
        $html = $this->load->view('certificates/'.$pg ,$data,true);


        $filename = 'TR'.$TransactionCertificate_ID."_".date('mYdHis');

        
        pdf_create($html, $filename,true);

}


What have i done wrong

Thanks in advance


Dompdf not working - El Forum - 02-10-2010

[eluser]Sbioko[/eluser]
Show your include/frame.cls.php file.


Dompdf not working - El Forum - 02-10-2010

[eluser]bhakti.thakkar[/eluser]
[code]
&lt;?php

class Frame {

/**
* The DOMNode object this frame represents
*
* @var DOMNode
*/
protected $_node;

/**
* Unique identifier for this frame. Used to reference this frame
* via the node.
*
* @var string
*/
protected $_id;

/**
* This frame's calculated style
*
* @var Style
*/
protected $_style;

/**
* This frame's original style. Needed for cases where frames are
* split across pages.
*
* @var Style
*/
protected $_original_style;

/**
* This frame's parent in the document tree.
*
* @var Frame
*/
protected $_parent;

/**
* This frame's first child. All children are handled as a
* doubly-linked list.
*
* @var Frame
*/
protected $_first_child;

/**
* This frame's last child.
*
* @var Frame
*/
protected $_last_child;

/**
* This frame's previous sibling in the document tree.
*
* @var Frame
*/
protected $_prev_sibling;

/**
* This frame's next sibling in the document tree.
*
* @var Frame
*/
protected $_next_sibling;

/**
* This frame's containing block (used in layout): array(x, y, w, h)
*
* @var array
*/
protected $_containing_block;

/**
* Position on the page of the top-left corner of the margin box of
* this frame: array(x,y)
*
* @var array
*/
protected $_position;

/**
* This frame's decorator
*
* @var Frame_Decorator
*/
protected $_decorator;

/**
* Class constructor
*
* @param DOMNode $node the DOMNode this frame represents
*/
function __construct(DomNode $node) {
$this->_node = $node;

$this->_parent = null;
$this->_first_child = null;
$this->_last_child = null;
$this->_prev_sibling = $this->_next_sibling = null;

$this->_style = null;
$this->_original_style = null;

$this->_containing_block = array("x" => null,
"y" => null,
"w" => null,
"h" => null);
$this->_position = array("x" => null,
"y" => null);

$this->_decorator = null;

//$this->set_id( uniqid(rand(),true) );
/*
if (!isset($GLOBALS['dompdfuniqueid']))
{
$GLOBALS['dompdfuniqueid'] = 1;
} else {
$this->set_id($GLOBALS['dompdfuniqueid']++);
}
*/
/*
global $dompdf_unique_id;
if (isset($dompdf_unique_id)) { $dompdf_unique_id++; } else { $dompdf_unique_id = 1; }
$this->set_id( $dompdf_unique_id );
*/
$this->set_id($GLOBALS['dompdfuniqueid']++);
}

/**
* "Destructor": forcibly free all references held by this frame
*
* @param bool $recursive if true, call dispose on all children
*/
function dispose($recursive = false) {

if ( $recursive ) {
while ( $child = $this->_first_child )
$child->dispose(true);
}

// Remove this frame from the tree
if ( $this->_prev_sibling ) {
$this->_prev_sibling->_next_sibling = $this->_next_sibling;
}

if ( $this->_next_sibling ) {
$this->_next_sibling->_prev_sibling = $this->_prev_sibling;
}

if ( $this->_parent && $this->_parent->_first_child === $this ) {
$this->_parent->_first_child = $this->_next_sibling;
}

if ( $this->_parent && $this->_parent->_last_child === $this ) {
$this->_parent->_last_child = $this->_prev_sibling;
}

if ( $this->_parent ) {
$this->_parent->get_node()->removeChild($this->_node);
}

$this->_style->dispose();
unset($this->_style);
$this->_original_style->dispose();
unset($this->_original_style);

}

// Re-initialize the frame
function reset() {
$this->_position = array("x" => null,
"y" => null);
$this->_containing_block = array("x" => null,
"y" => null,
"w" => null,
"h" => null);

unset(


Dompdf not working - El Forum - 02-11-2010

[eluser]bhakti.thakkar[/eluser]
The code is not full as the character length is a issue. Also i cannot attach the file in txt , html, pdf, doc as it has mime issue, Let me know which line you want... i will update those lines from frame.cls.php

Thanks


Dompdf not working - El Forum - 02-11-2010

[eluser]bhakti.thakkar[/eluser]
Hello,
Okay in the mean time, i get the solution for the above, I am thinking of opening the saved PDF directly from the server location.


Dompdf not working - El Forum - 02-11-2010

[eluser]Sbioko[/eluser]
So, are you still need my help?


Dompdf not working - El Forum - 02-11-2010

[eluser]jbreitweiser[/eluser]
Try setting the document type to pdf and just stream the results of your pdfobj directly to the usser. No need to write it to the servers file system.


Dompdf not working - El Forum - 02-11-2010

[eluser]Sbioko[/eluser]
Try to not use the $GLOBALS. You can put this unique id into the session(for example). Your script just does not see the $dompdf_unique_id variable. Make it global using other alternative ways.


Dompdf not working - El Forum - 02-11-2010

[eluser]bhakti.thakkar[/eluser]
Thanks Sbioko,
I replace
$this->set_id($GLOBALS['dompdfuniqueid']++);
WITH
$this->set_id( uniqid(rand()) );

in frame.cls.php and its working wonders!!!

Hope it helps someone


Dompdf not working - El Forum - 02-11-2010

[eluser]Sbioko[/eluser]
Good luck :-)