I need to serve pdf files through the controller, but I can't make them open in browser window. When I send response with pdf file, it renders gibberish, or if I follow example at http://symfony.com/doc/current/components/http_foundation/introduction.html#serving-files it downloads the file, but I need to open it in view mode, how can I do that?
Here's what I'v got so far:
return new Response(readfile('/file/path/file.pdf'), 200,
array('Content-Type' => 'application/pdf')
);
Am I missing something, or maybe there's something wrong with my php or apache configuration?
in vim's official website, the definition of vim is clear: vim the editor It is not pdf reader, it is not MS-Word reader. You can of course write a pdf reader with other language, e.g. Java with itext lib.
As of Laravel 5.2 documented under Other response types you can now use the file helper to display a file in the user's browser. You just need to send the contents of the file to the browser and tell it the content type rather than tell the browser to download it. $filename = 'test.
At the top right, click More Settings. At the bottom, click Show advanced settings. Under “Privacy”, click Content settings. Under “PDF Documents," check the box next to "Open PDF files in the default PDF viewer application.” (Uncheck this box if you want PDFs to open automatically when you click them.)
Found a solution:
Add BinaryFileResponse before controller class declaration from example
use Symfony\Component\HttpFoundation\BinaryFileResponse;
In controller action return BinaryFileResponse
return new BinaryFileResponse('/file/path/file.pdf');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With