Mihail Minkov
Mihail Minkov

Reputation: 2633

DOMPdf not generating PDF on production server, only showing code

I have a working DOMPdf generation from HTML on a local server. I uploaded it to my production server and from my first tests it seemed to be working. Now a couple of days ago I started receiving reports that the PDF generation only shows symbols and letters. So, I checked and did some testing and apparently the issue is somewhere between the DOMPdf library, PHP fpm and CodeIgniter.

The production server uses:

The site uses:

So, after playing around a little bit I noticed that if I used the PDF generation code outside of CodeIgniter it works normally, but if I try to use it inside the CodeIgniter instance, I get this:

enter image description here

My theory is that this is basically a header issue, but I am not sure what's causing it.

Upvotes: 0

Views: 1107

Answers (1)

Mihail Minkov
Mihail Minkov

Reputation: 2633

At the end I checked it with the CodeIgniter forum guys and I got two possible solutions. Evidently it was a header/buffer problem.

So, there are two options to fix this:

Option 1 - Removing the specific header for Content-Type

//in controller method
$this->response->removeHeader('Content-Type'); 

Option 2 - Adding an exit() command at the end of the code

$dompdf->stream("test.pdf",array('Attachment'=>0)); 
exit(); 

Upvotes: 2

Related Questions