Sending pdf to screen from controller [SOLVED]


#1

I am trying to show a pdf on the screen from a controller. I’ve tried everything I can think of, even using fpdf but I get a blank pdf. I have no problem downloading the pdf like this

 $response  = $response->withHeader('Content- Description', File_Transfer')
    ->withHeader('Content-Type', 'application/octet-stream')
    ->withHeader('ContentDisposition','attachment;filename="'.basename($file).'"')
    ->withHeader('Expires','0')
    ->withHeader('Cache-Control','must-revalidate')
    ->withHeader('Pragma','public')
    ->withHeader('Content-Length',filesize($file));
    readfile($file);

Is there a way to use with header to display a pdf?


#2

For anyone wondering it was simple I just did this,

$response = ->withHeader(‘Content-Type’, ‘application/pdf’)
->withHeader(‘Content-Disposition’ 'inline;filename=" ’ . basename($file) . ’ ");
readfile($file);