Welcome Guest, Not a member yet? Register   Sign In
DomPDF Broken
#1

[eluser]mdavis1982[/eluser]
Hi all...

I was using DomPDF whilst developing a site for a client and it was working wonderfully with all my test data... However, now that I have the real data in (there's much more of it - 3252 records) it's stopped working. I'm also using the ActiveRecord class from the Wiki.

Here's the code from my controller function:
Code:
function generateCatalogue()
{
    $this->load->model('artist');
    $this->db->orderby('sort_name', 'ASC');
    $allArtists = $this->artist->find(ALL);
            
    foreach($allArtists as $artist)
    {
        $artist->fetch_related_tracks('track', 'ORDER BY tracks.sort_title ASC');
                
        foreach($artist->tracks as $track)
        {
            $newTrack = $this->track->find_by_id($track->id);
            $newTrack->fetch_related_artists();
            $newTrack->fetch_related_trackversions();
                    
            $data['tracks'][] = $newTrack;
            $newTrack = NULL;
        }
                
        $artist = NULL;
    }
            
            
    $this->load->plugin('to_pdf');            
    $html = $this->load->view('catalogue/catalogue', $data, true);

    $this->load->helper('file');
    pdf_create($html, 'catalogue.pdf', $this->config->item('mbt_catalogue_path'), FALSE);
}

And in my to_pdf_pi.php file:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function pdf_create($html, $filename, $path = '', $stream = TRUE)
{
    require_once('dompdf/dompdf_config.inc.php');
    
    $dompdf = new DOMPDF();
    $dompdf->set_paper('a4');
    $dompdf->load_html($html);
    $dompdf->render();
    
    if ($stream)
    {
        $dompdf->stream($filename);
    }
    else
    {
    if (file_exists($path . $filename))
    {
        unlink($path . $filename);
    }
            
        write_file($path . $filename, $dompdf->output());
    }
}

?>

If I echo out the $html in my controller I get all the data presented on the screen, but when trying to create the PDF I get the error:
Quote:Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 6291456 bytes) in /Users/matt/Sites/mbtadmin/system/plugins/dompdf/include/frame_tree.cls.php on line 169

I've tried changing my memory limit in php.ini up to 512mb, but still get the same kinds of errors (and this wouldn't be practical on the hosting for the client's site anyway). If anyone could help me fix this error I would be most appreciative!

Thanks guys...

Matt
#2

[eluser]mdavis1982[/eluser]
I forgot to post the content of my view:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
    &lt;head&gt;
        &lt;link rel="stylesheet" href="catalogue.css" type="text/css" /&gt;
        &lt;style type="text/css"&gt;
        body
        {
            background-color: transparent;
            font-family: Helvetica, sans-serif;
            font-size: 0.65em;
            margin: 0.25in;
        }
        
        #header
        {
            text-align: center;
        }
        
        #header h1
        {
            font-size: 1.4em;
            margin-bottom: 0;
        }
        
        #header h2
        {
            font-size: 1.2em;
            margin-top: 0;
        }
        
        #content table
        {
            width: 100%;
            border-collapse: collapse;
            vertical-align: middle;
        }
        
        #content table tr th
        {
            text-align: left;
            border: 1px solid black;
            background-color: #345383;
            color: #fff;
        }
        
        #content table tr td.centered, #content table tr th.centered
        {
            text-align: center;
            width: 0.6in;
        }
        
        #content table tr td
        {
            border-left: 1px solid black;
            border-right: 1px solid black;
            border-bottom: 1px solid black;
            background-color: #f2f2f2;
        }
        
        #content table tr td, #content table tr th
        {
            padding: 0.05in;
        }
        &lt;/style&gt;
    &lt;/head&gt;

    &lt;body&gt;
        <div id="header">
            <img src="&lt;?php echo base_url() . '/public/images/site/branding/logo.jpg'; ?&gt;" />
            <h1>MusicBackingTracks.co.uk Catalogue</h1>
            <h2>Last Updated: &lt;?php echo date('d/m/Y', mktime()); ?&gt;</h2>
        </div>
        <div id="content">
            <table>
                <tr>
                    <th>Artist</th>
                    <th>Song Title</th>
                    <th class="centered">Backing Vocals</th>
                    <th class="centered">Female Lead</th>
                    <th class="centered">Male Lead</th>
                    <th class="centered">For Duet</th>
                    <th class="centered">Catalogue #</th>
                </tr>
                &lt;?php foreach($tracks as $track): ?&gt;
                    &lt;?php foreach($track->trackversions as $version): ?&gt;
                        <tr>
                            <td>&lt;?php echo $track->artists[0]->name; ?&gt;</td>
                            <td>&lt;?php echo $track->title; ?&gt;</td>
                            <td class="centered">&lt;?php echo ($version->backing_vocals) ? 'Yes' : 'No'; ?&gt;</td>
                            <td class="centered">&lt;?php echo ($version->female_lead) ? 'Yes' : 'No'; ?&gt;</td>
                            <td class="centered">&lt;?php echo ($version->male_lead) ? 'Yes' : 'No'; ?&gt;</td>
                            <td class="centered">&lt;?php echo ($version->for_duet) ? 'Yes' : 'No'; ?&gt;</td>
                            <td class="centered">&lt;?php echo $version->id; ?&gt;</td>
                        </tr>
                    &lt;?php endforeach; ?&gt;
                &lt;?php endforeach; ?&gt;
                            
            </table>
        </div>
    &lt;/body&gt;
&lt;/html&gt;

Thanks!

Matt
#3

[eluser]nandish[/eluser]
set the memory in plugin file
ini_set("memory_limit","32M");
#4

[eluser]Brad Martin[/eluser]
I have the same problem as above too. Its a memory issue but i can't seem to work out how to get around it.

Where abouts in the plugin file to you set the limit ? Ive tried in the controller and then in the library file and also in the dompdf file as well but no luck so far Sad




Theme © iAndrew 2016 - Forum software by © MyBB