Controlling how a PDF will be served to the user by the browser can be hard and not 100% effective. But we have a few options that will let us make it work for most of our user base.
When a file is sent as a HTTP response to the browser, the information about how to treat this file is located in the HTTP headers. The browser will decide what to do with the response based on how it is configured and what is installed on the OS.
With RotativaHQ you have a few parameters to help.
- If you don’t define a
FileNameproperty then the PDF should be served by the browser inline inside the browser window. If the user wishes to download it then it will default its name to a unique id assigned by RotativaHQ. As will happen will this code:
- If you define a
FileNameproperty, then the browser will, either prompt te user asking if it needs to save or open the file, or just download it (the latter should be the case for Chrome). This code will give achieve this:
- If you define both the
FileNameproperty and the
true, then the browser should show the file inside the browser window and show the defined file name as default when saving. As this sample code:
This options should work most of the times. Of course we can’t know if the user has installed any PDF reader or if the browser itself has a embedded reader or the user has installed a browser plugin to read PDF files. But still, with those options we are able to send to the browser the correct HTTP headers.