I have a link to a PDF and when I click on it I want it to open a new tab and render in the new tab as opposed to asking me to download it. How do I do that?
note, I'm asking this question so I can answer it. This information can be pieced together from other answers, but I'd like it to be all in one place
To open a link in a new tab (PDF or not) you must modify the HTML of that link from
<a href="/link_to_pdf.pdf">PDF</a>
to
<a href="/link_to_pdf.pdf" target="_blank">PDF</a>
To open a PDF in the browser you must make a server side change to the response header. In Java, you would do this:
response.setContentType("application/pdf");
response.addHeader("content-disposition", "inline; filename=link_to_pdf.pdf");
Of key importance is the inline
. If you put attachment
, your browser will try to download it instead. You can read more here.
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