禁用网页上显示的 PDF 菜单选项
我正在网页上显示 PDF。该网页是一个弹出窗口。代码是:
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();
这一切都很好。 由于业务要求和欺诈原因,用户必须:
- 只打印一次(然后窗口应该在可能的情况下自行关闭)
- 不允许用户保存 pdf
我已经在谷歌上到处搜索了,看起来你什么也做不了,比如例如,禁用“保存”按钮,但只是想我会在这里发布,看看是否有人以前遇到过这个问题并设法找到解决方案? 谢谢!
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:
- only print once (and then the window should close itself if possible)
- not allow the user to save the pdf
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
坏消息
当您在浏览器中“查看” PDF 时,您已经将其“保存”到您的计算机上。如果您将这一点与网络上的其他所有内容(网页、图像等)进行比较,它实际上很有意义。因此,禁用“保存”将首先禁用“下载”,这不是您想要的。
同样的想法也适用于印刷。您可以使图像只能打印一次吗? (实际上是的,见下文。)另一个问题是,是否打印某些内容是文档级问题,首先由 PDF 查看器的实现者来实现。由于这不是 PDF 规范的一部分,因此实际上没有任何兴趣这样做。另外,“打印一次”首先意味着什么?我只能按一次打印按钮吗?我可以打印一次并选择 500 份吗?由于打印被卸载到打印驱动程序/操作系统,因此也需要传递“安全信息”。一旦打印出来,我显然可以扫描并重新打印它。事实上,我可以打印到 PDF/PostScript 并获得原始的不安全版本。
Adobe Acrobat 中的一些安全设置似乎是一个值得尝试的好主意,但它们也不会让您走得太远。如果您在 Acrobat 中打开 PDF 并转到“高级”、“安全性”、“使用密码加密”,您至少可以禁用使用密码对 PDF 进行的更改。有趣的是,如果您禁用更改,它实际上会禁用 Adobe Reader/Acrobat 中的“保存”按钮。相反,它会强制您另存为,但我看到很多人“认为”保存已被禁用。不幸的是,对于打印,您无法采取太多措施来锁定它。
好消息
很抱歉在您的要求中指出了一些漏洞。听起来很像优惠券公司的做法,他们只希望您能够打印一次。我会尝试模仿他们的做法。或者可能更好,谷歌日历曾经做过类似的事情(尽管似乎不再这样做了)。 Google 过去常常向您展示文档(只是 JPG)的“打印预览”,当您点击打印时,它会使用 IFRAME、AJAX 或 OBJECT 将资源异步加载到隐藏容器中,然后进行打印。 这里有一篇文章详细讨论了这一点 。按照这条路线,您可以使用常规编程逻辑在打印后禁用您自己的 HTML 打印按钮。当然,如果有人单击“打印”但随后取消了打印对话框,那么他们就不走运了。
您可以做的另一件事是将一些参数传递给 PDF,以在显示 PDF 时禁用内置工具栏。具体来说,您可以发送
somefile.pdf?toolbar=0
。 有关详细信息,请参阅此文档 。请注意,这些设置仅适用于 Adobe Acrobat/Reader。 Chrome、Safari 和其他浏览器都有自己的 PDF 渲染器。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.