How to disable download option of pdf file in c# ?

2019-09-21 01:28发布

问题:

How to disable the pdf Toolbar because I don't want to give the download option to the pdf viewers.

I have used Iframe for showing Pdf File please find the following code

<iframe ID="iFrame2" runat="server" align="bottom" frameborder="2" name="iframe1" height="500" width="600" src="~/pdffiles/example.pdf"></iframe>

Please help me to disable the download option using c#.

Thanks

回答1:

You cant. It is a browser feature which means you have no control over it. You can use third party tools like Google Document Viewer or change the format of your document to an image.

Google Document Viewer



回答2:

If you want to avoid that an end user saves a PDF document, you are asking something that is impossible. The only way to avoid that an end user doesn't have a copy of the PDF is by not sending him the PDF. A PDF can't be opened in Adobe Reader without having the actual bytes on the disk. Even if you would disable saving (for instance in the context of a web application), you'd always find the PDF somewhere in the temp files and people would be able to copy that file as many times as they want.

Trying to hide the toolbar (a viewer preference) doesn't make sense. Whether or not this viewer preference will be respected entirely depends on the PDF viewer. For instance: in Adobe Reader X and later, you have a special widget (HUD or Heads Up Display) that appears when you hover over the document. This widget allows users to save the document.

Let me quote Adobe:

the "Heads Up Display" (HUD) is not customizable. There are no APIs to HUD. You can’t use JavaScript to enter Read Mode, exit Read Mode or detect that the document is in Read Mode. Though it might seem like it, this wasn’t an oversight. There are some very sound engineering reasons why this is the case but I won’t go into those here.

Even with Adobe Reader 9, hiding the toolbar isn't sufficient: if the user chooses the appropriate menu item or hits the appropriate "hot key", the toolbar would appear and they could happily click the Save button. In addition, they could have right-clicked and chosen "Save" as well.

In short, you're asking the wrong question (and that probably explains the downvotes given by several people).



标签: c# pdf iframe