Display PDF on browser
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.
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.
Instead of using
@readfile($file);
Use
echo file_get_contents($file);
Or ommit the @
$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.