怎么能有密码保护的PDF文件以编程方式打开? [英] how can a password-protected PDF file be opened programmatically?
问题描述
使用Adobe IFilter的不提供给提供密码以打开一个密码保护的PDF文件夹机构,因此它不能被用来打开密码保护的文件。
The Adobe IFilter doesn't provide a mechanism to supply a password to open a password-protected PDF file, so it cannot be used to open password-protected files.
我想知道,是否有一个比较简单的方法以编程方式检索的PDF文件中的实际加密的数据,利用标准的加密API解密,然后使用解密的数据建立一个新的PDF文件?
I was wondering, is there a relatively straightforward way to programmatically retrieve the actual encrypted data inside the PDF file, decrypt it using a standard cryptography API, and then build a new PDF file with the decrypted data?
推荐答案
要打开密码保护的PDF文档,你将需要至少开发一个PDF解析器,解密和发电机。我不建议这样做,虽然。这是远不及一件容易的事来完成。
To open a password protected PDF you will need to develop at least a PDF parser, decryptor and generator. I wouldn't recommend to do that, though. It's nowhere near an easy task to accomplish.
使用的PDF库的一切帮助是非常简单的。你可能会想尝试 Docotic.Pdf库的任务(声明:我的供应商合作图书馆)。
With help of a PDF library everything is much simpler. You might want to try Docotic.Pdf library for the task (disclaimer: I work for the vendor of the library).
下面是给你的任务的例子:
Here is a sample for you task:
public static void unprotectPdf(string input, string output)
{
bool passwordProtected = PdfDocument.IsPasswordProtected(input);
if (passwordProtected)
{
string password = null; // retrieve the password somehow
using (PdfDocument doc = new PdfDocument(input, password))
{
// clear both passwords in order
// to produce unprotected document
doc.OwnerPassword = "";
doc.UserPassword = "";
doc.Save(output);
}
}
else
{
// no decryption is required
File.Copy(input, output, true);
}
}
Docotic.Pdf可以从PDF文件也提取文本(格式化与否)一>。它可能是有用的索引(我想这是你是什么最多,因为你提到的Adobe的IFilter)
Docotic.Pdf can also extract text (formatted or not) from PDFs. It might be useful for indexing (I guess it's what you are up to because you mentioned Adobe IFilter)
这篇关于怎么能有密码保护的PDF文件以编程方式打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!