Welcome Guest, Not a member yet? Register   Sign In
Showing pdf on browser
#1

I need a way to show a pdf file on browser in codeignter v4.4.0 or later. I have tried inline method in download response but it always downloads the pdf file.

$this->response->download(.......)->inline();

even setting headers have not helped

return $this->response
            ->setHeader('Pragma','public')
            ->setHeader('Expires','0')
            ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
            ->setHeader('Content-Disposition','inline; filename="'.$filename.'"')
            ->setContentType('application/pdf')
            ->setHeader('Content-Length',strlen($data))
            ->download($filename,$data,true);

Would you please help me?
Reply
#2

How to open a PDF files in web browser using PHP?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

This worked.

return $this->response->download(WRITEPATH . 'patterna.pdf', null)
    ->setContentType('application/pdf')
    ->inline()
    ;
Reply
#4

(04-16-2024, 02:07 AM)kenjis Wrote: This worked.

return $this->response->download(WRITEPATH . 'patterna.pdf', null)
    ->setContentType('application/pdf')
    ->inline()
    ;

Thank you kenjis. It works great.
Of course I should disable "Internet Download Manager program" so the pdf be shown on the browser. In v3.4.8 and older the pdf file was shown without disabling that program when I set the headers.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB