Ok took me a little while but I got it to work like below.
PHP Code:
// -------------------------------------------------------------------
/**
* displayPdf ()
* -------------------------------------------------------------------
*
*
*/
public function displayPdf()
{
// Store the file name into variable
// The location of the PDF file on the server
$file = WRITEPATH . 'pdf/CodeIgniterAjaxPagination.pdf';
$fileName = 'CodeIgniterAjaxPagination.pdf';
// Header content type
$this->response->setHeader('Content-Type', 'application/pdf');
header('Content-Disposition: inline; filename="' . $fileName . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
// Read the file
readfile($file);
}
So it looks like we just needed to use CodeIgniters
PHP Code:
$this->response->setHeader('Content-Type', 'application/pdf');
At that's it.
This one I could not get to work with CodeIgniter for some reason.
PHP Code:
header('Content-Disposition: inline; filename="' . $fileName . '"');
Figured it out this is how to display a pdf file using CodeIgniter 4
PHP Code:
$this->response->setHeader();
Here is the new method on how it is done and working, you will need to change the
top two lines to you pdf path and filename.
PHP Code:
// -------------------------------------------------------------------
/**
* displayPdf ()
* -------------------------------------------------------------------
*
* Displays a pdf file into the users web browser using php.
*/
public function displayPdf()
{
// Store the path location of the PDF file on the server into a php property.
$file = WRITEPATH . 'pdf/CodeIgniterAjaxPagination.pdf';
// Store the file name into php property.
$fileName = 'CodeIgniterAjaxPagination.pdf';
// Set header content type.
$this->response->setHeader('Content-Type', 'application/pdf');
$this->response->setHeader('Content-Disposition: inline;', 'filename="' . $fileName . '"');
$this->response->setHeader('Content-Transfer-Encoding', 'binary');
$this->response->setHeader('Content-Length: '. filesize($file),'');
$this->response->setHeader('Accept-Ranges:', 'bytes');
// Read the file.
readfile($file);
}
Tested an working on my Windows 10 Pro x64 Build 2004
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )