Welcome Guest, Not a member yet? Register   Sign In
Big Problem With DomPDF
#1

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

I'm trying to get DomPDF working with CI using Derek's Wiki entry as a guide (http://www.codeigniter.com/wiki/PDF_gene...ng_dompdf/).

I have the following in my to_pdf_pi.php file (located in system/plugins/)
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->load_html($html);
        $dompdf->render();
    
        if ($stream)
        {
            $dompdf->stream($filename . '.pdf');
        }
        else
        {
            write_file($path . $filename . '.pdf', $dompdf->output());
        }
    }

?>

I've got the following in my controller:
Code:
function test()
{
    $this->load->plugin('to_pdf');
    $data['title'] = 'Test PDF';
    $html = $this->load->view('test', $data, true);
    pdf_create($html, 'test');
}

And I have the following in my view file (it's just one of the demos from the DomPDF distribution at the moment):
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;style&gt;
.d { width: 1in; height: 1in; margin: 5pt; }

.b1 {
  border: 1px solid red;
}

.b2 {
  border: solid thick blue;
}

.b3 {
  border: #369 thin dashed;
}

.b4 {
  border: dotted green 2px;
}

.b5 {
  border: 0.1em #0033DD solid;
}

.b6 {
  border: orange inset 4pt;
}

&lt;/head&gt;
&lt;body&gt;
<div class="d b1"> </div>
<div class="d b2"> </div>
<div class="d b3"> </div>
<div class="d b4"> </div>
<div class="d b5"> </div>
<div class="d b6"> </div>
&lt;/body&gt;
&lt;/html&gt;

When I try to run the function from my controller I get the following error messages:

Quote:A PHP Error was encountered

Severity: Warning

Message: file_put_contents(/Users/matt/Sites/mbtadmin/system/plugins/dompdf/lib/fonts/php_Times-Roman.afm) [function.file-put-contents]: failed to open stream: Permission denied

Filename: lib/class.pdf.php

Line Number: 2354

Unable to stream pdf: headers already sent

If anyone could help me to solve this I would be most grateful as I have to get it working today for a client's site!

If anyone is wondering as well, I'm developing on Mac OS X 10.5.1, PHP 5.2.4, CI 1.5.3 and DomPDF 0.5.1.

Thanks in advance guys...

Matt
#2

[eluser]mdavis1982[/eluser]
Okay.. I think I have fixed it now...

Basically there was a permissions error on the dompdf/lib/fonts/ directory. Using chmod a+x on it made everything work as expected!

Hope this maybe helps someone!

Cheers...

Matt
#3

[eluser]Derek Allard[/eluser]
Yea! Nice catch Matt. Thanks for writing back Wink
#4

[eluser]yesov[/eluser]
Hi!
i have a similar problem.
if i set $stream=TRUE see "Unable to stream pdf: headers already sent" without any errors.
and permision for folders is 777
what's wrong ?
#5

[eluser]industrial[/eluser]
Hi! Are having the same issue, did you solve it?
#6

[eluser]industrial[/eluser]
[quote author="industrial" date="1256518103"]Hi! Are having the same issue, did you solve it?[/quote]

Big shame on me for not googling properly! Here's a solution that did solve my issue:
http://ellislab.com/forums/viewthread/89418/

What I did was to remove the ending ?&gt; at the plugin file and Dompdf now works as a charm!
#7

[eluser]uk81[/eluser]
Hi.

I had an similar error.
Got also the message:
Code:
Severity: Warning
Message:  file_put_contents(/opt/app/pac/htdocs/system/plugins/dompdf/lib/fonts/php_Times-Roman.afm): failed to open stream: Permission denied
Filename: lib/class.pdf.php
Line Number: 2354

But the suggestions from above doesn´t work / help. Than I searched the internet and found the files php_Times-Roman.afm (and also as italic and bold) to download from a server.
I download the files and put it into the dompdf/lib/fonts/ folder and now it works.

The problem was:
The 3 Times-Roman afm-files were not in the fonts-folder.

Now it works fine. Smile




Theme © iAndrew 2016 - Forum software by © MyBB