如何使用c#打开受密码保护的pdf

CMM*_*ung 2 c# pdf adobe password-protection itextsharp

我想在c#.net windows应用程序面板或adobe reader中打开受密码保护的pdf.

我的想法是我想通过系统传递密码并打开pdf.用户可以看到pdf但无法保存.即使用户可以将我们保存在他们的计算机中,当他们重新打开pdf时,该文件也会询问密码.这意味着当他们想要阅读pdf时,他们必须使用系统,如果他们将pdf带到外面,他们就无法打开密码的cos.

我试过用Adobe Pdf dll,这个不能传递密码.而且我也试过用itextsharp,这个可以传递密码但是在传递密码之后,需要保存pdf.因此,当我打开pdf时,该文件没有密码.

我想通过系统直接打开受密码保护的pdf.我不想再保存.

Ekk*_*Ekk 5

有一个类似的问题如何以编程方式打开受密码保护的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); 
    } 
} 
Run Code Online (Sandbox Code Playgroud)