CodeIgniter Forums
Displaying PDF - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Displaying PDF (/thread-70908.html)

Displaying PDF - donpwinston - 06-15-2018

I've been getting errors in my php_error_log file. The error occur in pairs (same timestamp). But my application runs fine.

[15-Jun-2018 11:33:42 America/New_York] PHP Fatal error:  Uncaught ErrorException: Cannot modify header information - headers already sent in /opt/lampp/htdocs/system/Debug/Exceptions.php:139

Stack trace:
#0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', '/opt/lampp/htdo...', 139, Array)
#1 /opt/lampp/htdocs/system/Debug/Exceptions.php(139): header('HTTP/1.1 500 In...', true, 500)
#2 /opt/lampp/htdocs/system/Debug/Exceptions.php(200): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException))
#3 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#4 {main}
  thrown in /opt/lampp/htdocs/system/Debug/Exceptions.php on line 139

The relevant code called from a controller is:

PHP Code:
header('Cache-Control: private');
header('Content-type: application/pdf');

Any ideas?

RE: Displaying PDF - donpwinston - 06-20-2018

Has anyone tried displaying a PDF file using CI4? If I do it with the above code I get an error in my php_error_log file. But it works, I get the PDF display. If I remove the ob_clean; flush(); statements then I get the error on the screen and no PDF.

RE: Displaying PDF - InsiteFX - 06-21-2018

You should be able to display it in an html iframe loading the file, but the web browser should also display it.

RE: Displaying PDF - donpwinston - 04-25-2019

Use the following:
$this->response->setHeader('Cache-Control', 'private');
$this->response->setHeader('Content-type', 'application/pdf');