繁体   English   中英

如何使用VB6 / VB.NET打开受密码保护的PDF?

[英]How to open a password protected PDF using VB6/VB.NET?

我想在VB6 / VB.NET程序中打开查看密码保护的PDF文件。 我尝试过使用Acrobat PDF Library但却无法使用它。

我想创建受密码保护的PDF文件的原因是因为我不想在没有外部密码的情况下打开PDF文件,即在程序之外。

要打开受密码保护的PDF,您需要至少开发PDF解析器,解密器和生成器。 不过,我不建议这样做。 完成任务并不容易。

借助PDF库,一切都更简单。 您可能想要为此任务尝试Docotic.Pdf库。

以下是您的任务示例:

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)

你可以通过互联网将代码转换为vb

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM