使用iTextsharp加密pdf,同时下载文件并在浏览器中无密码打开 [英] Encrypt pdf with password using iTextsharp while downloading the file and open without password in browser

查看:110
本文介绍了使用iTextsharp加密pdf,同时下载文件并在浏览器中无密码打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以这样的方式加密pdf文件:当用户尝试通过应用程序打开pdf文件时,用户应该能够在不输入密码的情况下查看文档(即,密码应该以编程方式传递)。此外,当用户尝试从浏览器下载相同的文件并打开下载的文件时,它应该要求加密的密码打开文件。



什么我试过了:



我曾尝试使用iTextSharp并加密pdf,但它会在查看和下载时加密密码。但是我只有在从浏览器下载pdf时才需要密码保护,而不是在浏览器中查看时。

I need to encrypt the pdf file in such a manner that when user tries to open the pdf file through application, user should be able to view the document without entering the password (i.e., the password should be passed programmatically). Also, when user tries to download the same file from the browser and opens the downloaded file, it should ask the encrypted password to open the file.

What I have tried:

I have tried to use iTextSharp and encrypt the pdf, but it will encrypt the password while viewing and downloading. but I need the password protection only when I download the pdf from browser and not when I view in browser.

推荐答案

你不能这样做。

PDF文件受密码保护 - 在这种情况下用户需要输入密码 - 或者不是:没有可选密码,因为密码充当保护内容的加密密钥。 br />


当您将PDF文件传递给浏览器时,您无法真正控制它发生的情况:用户可以随意保存查看。如果您对自己说哦,他正在查看并提供了该文档的无密码版本,可以在以后没有密码的任何PDF查看器中保存和查看。
You can't do that.
A PDF file is either password protected - in which case the user needs to enter the password - or it isn't: there is no "optional password" as the password acts as an encryption key to protect the content.

When you pass a PDF file to the browser, you have no real control over what happens to it: the user can save of view it as they please. If you said to yourself "oh, he's viewing" and provided a password-free version of the document, it could be saved and viewed in any PDF viewer without the password later.


这篇关于使用iTextsharp加密pdf,同时下载文件并在浏览器中无密码打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆