Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Dec 29, 2022 4:41 pm

Hello,

our client have a lot of protected pdf documents uploaded in our system. They want from us to remove the protection and provided some passwords. I'm trying to achieve the goal with the following code:

Code: Select all
foreach (var doc in dir.GetFiles("*.pdf"))
{
    using (var pdf = new PdfDocument())
    {
        var ok = false;
        for (int i = 0; i < pws.Count; i++)
        {
            try
            {
                pdf.LoadFromFile(doc.FullName, pws[i]);
                pdf.Security.DecryptUserPassWord(pws[i]);
                ok = true;
                docOk++;
                break;
            }
            catch { }
        }
        if(!ok)
            docNotOk++;
    }
}

Console.WriteLine($"ok: {docOk}, not ok: {docNotOk}");


For 1/3 of documents this works fine, but not for all of them. The client ensured us they use only provided passwords.

Is this the right approach? Any ideas or suggestions are welcome.

Some screenshots are attached.

profiler007
 
Posts: 73
Joined: Wed Nov 13, 2019 11:32 am

Fri Dec 30, 2022 10:16 am

Hi,

Thanks for your inquiry.
Kindly note that pdf file possesses 2 kinds of password, the viewing password and editing password.
pass.png

I simulated a pdf file with viewing password “firstfile” and editing password “firstpdf”, using your major code, the decryption threw exception, see followed picture:
error.png

I guess that some files contain both viewing and editing password, if so, you need to use the following code:
pdf.Security.DecryptOwnerPassWord(editingPass);
result.png

If your issue still exists, please provide us with the following information to help us work out a solution for you. You can send them to us via email([email protected]) or attach them here. Thanks for your assistance in advance.
1) some of your test files which do not contain sensitive information.
2) your full code that can reproduce your issue.
3) the version of Spire.PDF in your project.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Jan 09, 2023 7:12 am

Hi,

Greetings from E-iceblue.
Could you please let us know how is your issue going now? if it has not been solved yet, please provide us with the following messages, you can send them to us via email([email protected]) or attach them here.
1) some of your test files which do not contain sensitive information.
2) your full code that can reproduce your issue.
3) the version of Spire.PDF in your project.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF

cron