13 ms·
At a previous gig I was working on a web app where there was a requirement for users to be able to "view PDFs without downloading them" (the product person's wo
by alexjplant 3y ago
At a previous gig I was working on a web app where there was a requirement for users to be able to "view PDFs without downloading them" (the product person's words, not mine, and they probably got it from somebody in security). I explained that such a thing was technically impossible as the act of rendering the PDF in the browser meant that the computer would have to download it. "There's no way to remove the download button?" they asked in response. No, there wasn't, because each browser would use its own PDF viewer or open the document in one installed on the machine. What if we used our own renderer instead though? After thinking for a second I remembered that PDF.js was a thing in Firefox... would it run in other browsers? Sure enough it did. I was able to fork it, remove save functionality (just a button and a context menu IIRC), and rig it up to load a PDF from our server.
The demo ran great in IE and Chrome, the two browsers that we had to support. Everybody seemed satisfied with this solution and called it a day. I have no idea whether this made it to production as I left shortly thereafter, but the fact that it passed muster didn't leave me with a great feeling.
- jowea 3y agoThe stupider solution would probably be converting the PDF to an image on the server and sending that to the browser.