Last time, I had introduced methods about PDF security, including how to encrypt PDF and add digital certificate. In this post, I want to show another method about how to decrypt PDF document with C#/VB.NET.
In my example, I have an encrypted PDF document, which saves an image about employee information. What I will do is to decrypt this document with password and extract image from it.
Also, I use s component Spire.PDF in my method. Therefore, I add its dll file as reference when starting with the following steps.
- Declare a string encryptedPdf and assign its value as the document which has been encrypted. Then, create a new PDF document. There are two parameters passed to PdfDocument method, string encryptedPdf and password, which is used to open the encrypted document. It means that the new PDF document we create is original document which has been decrypted.
- Extract Image. Suppose that there are many pages in document. We need to extract images from each page.
- Save and launch image file.
static void Main(string args)
String encryptedPdf = @”D:\work\My Documents\Encryption.pdf”;
PdfDocument doc = new PdfDocument(encryptedPdf, “123456”);
Image image = doc.Pages.ImagesInfo.Image;
Dim encryptedPdf As String = “D:\work\My Documents\Encryption.pdf”
Dim doc As New PdfDocument(encryptedPdf, “123456”)
Dim image As Image = doc.Pages(0).ImagesInfo(0).Image
Result Shown by Following:
Click Here to Learn more about Spire.PDF
Click Here to Download Spire.PDF