Foxit Quick PDF Library

Programmatically remove a password from a PDF

The ease with which you can remove a password from a PDF document depends on whether you have the user password. If the user password is known then removing security from a PDF is as simple as loading a document using the LoadFromFile function and at the same time including the user password in the password parameter option, then calling the Decrypt function and SaveToFile to save the changes.

// Load a file from the samples folder

QP.LoadFromFile("encrypted.pdf", "mypassword"); 

// Call the Decrypt function to remove the security
QP.Decrypt();

// Save the decrypted file
QP.SaveToFile("decrypted.pdf");

As you can see it is technically possible to decrypt a PDF using only the user password — it is not necessary to have the master password. In addition, if a PDF is only encrypted with a master password — that is, it does not have a user password — then it is possible to decrypt the PDF using the same code above, just by passing an empty password string to the LoadFromFile function. A master password by itself cannot prevent decryption.

If a PDF includes both a user password and master password then it cannot be decrypted without first breaking the encryption. This is not something that our library is able to do.

We recommend that all of our customers who wish to secure their PDFs use both a user and a master password to secure the PDF.

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: