Display PDF on browser Display PDF on browser codeigniter codeigniter

Display PDF on browser


$filePath="file path here";$filename="file name here";header('Content-type:application/pdf');header('Content-disposition: inline; filename="'.$filename.'"');header('content-Transfer-Encoding:binary');header('Accept-Ranges:bytes');@ readfile($filePath);

please try this code i hope it will working as i try.


you can use PDF Merger library to achive your goals.Here is the link to original library (outdated). Prefer myokyawhtun fork which is maintained

and a sample code will be as following

include 'PDFMerger.php';$pdf = new PDFMerger;$pdf->addPDF('path_to_pdf/one.pdf', '1, 3, 4')  //include file1 - pages 1,3,4    ->addPDF('path_to_pdf/two.pdf', '1-2')      //include file2 -  pages 1 to 2    ->addPDF('path_to_pdf/three.pdf', 'all')    //include file3 - all pages    ->merge('browser', 'test.pdf');  // OUTPUT : make sure you choose browser mode here.

Supported modes - browser, file, download and string.


Edit : As i can see you have tagged CI you can put PDFMerger.php in applications/libraries.and load it in autoload.php or in controller

and then can use it like $this->pdfmerger->addPDF() and merge() functions.


Use exit after readfile:

$filepath = 'your-path/demo.pdf';header('Content-Type: application/pdf');header(sprintf("Content-disposition: inline;filename=%s", basename($filepath)));@readfile($filepath);exit;

ps. @ before readfile it's used to suppress errors, maybe remove it in dev mode.