Reputation: 161
I am displaying a PDF on a webpage. The webpage is a popup window. The code is:
string filePath = @"C:\TempPDF\Sample.PDF";
bytes = rv.ServerReport.Render("PDF", null, out mimeType, out encoding,
out extension, out streamIds, out warnings);
FileStream fileStream = new FileStream(filePath, FileMode.Create);
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Close();
File.Delete(filePath);
Response.ClearContent();
// write file to browser
Response.BinaryWrite(bytes);
Response.Flush();
This all works fine. Due to business requirements and for fraud reasons the user must:
I have googled everywhere and it seems like you can't do anything , like disabling the Save button for example but just thought I would put out here to see if anyone has come across this before and managed to find a solution? Thanks!
Upvotes: 0
Views: 5313
Reputation: 55427
The Bad News
When you "view" a PDF in your browser you've already "saved" it to your machine. If you think about this compared to everything else on the web (web pages, images, etc) it actually makes a lot of sense. So to disable "saving" would be to disable "downloading" in the first place which is not what you want.
The same idea is true for printing. Can you make an image printable only once? (Actually yes, see below.) The other problem is that whether something has been printed or not is a document-level question and would be up to the implementers of the PDF viewer to implement in the first place. Since that isn't part of the PDF spec there really isn't any interest in doing that. And also, what does "print once" mean in the first place? I can only press the print button once? Can I print once and select 500 copies? Since printing is offloaded to the print driver/OS this "security information" would need to be passed along, too. Once printed, I can obviously scan and reprint it anyway. In fact, I could print to PDF/PostScript and get the raw unsecured version anyway.
Within Adobe Acrobat there are some security settings that might seem like a good idea to try but they also won't get you too far. If you open a PDF in Acrobat and go to Advanced, Security, Encrypt with Password you can at least disable changes to the PDF with a password. An interesting thing, if you disable changes it actually disables the Save button in Adobe Reader/Acrobat. Instead it forces you to Save As but I've seen a lot of people "think" that Save was disabled. For printing there isn't much that you can do to lock it down unfortunately.
The Good News
Sorry to poke a bunch of holes in your requirements. Sounds very much like what coupon companies do where they only want you to be able to print one time. I would try to mimic what they do. Or possibly even better, Google Calendar used to do something similar (although appears to not do it anymore). Google used to show you a "print preview" of a document (just a JPG) and when you hit print it would load a resource async into a hidden container, either using an IFRAME, AJAX or OBJECT, and then print that. Here's a post that talks more about that. Going this route you can use your regular programming logic to disable your own HTML print button after printing. Of course, if someone clicks print but then cancels the print dialog they're out of luck.
The other thing that you can do is pass some parameters to the PDF to disable the built-in toolbars when displaying a PDF. Specifically you could send somefile.pdf?toolbar=0
. See this document for more information. Note, these settings only apply to Adobe Acrobat/Reader. Chrome, Safari and other browsers have their own PDF renderers.
Upvotes: 1