Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Removing a password

Question

What steps are necessary to remove the password from a PDF file and save a copy without the password?

Answer

It depends on what sort of security is used in your PDF document. I've included a couple of code samples below that demonstrate how to remove security from PDFs with basic security and also how to remove security from PDFs with more advanced security (encrypted content streams).

// Load a file from the samples folder
QP.LoadFromFile("encrypted.pdf"); 

// Before we call the Decrypt function, we need
// to set the password.

QP.SetPassword("locked_down");

// Call the Decrypt function
QP.Decrypt();

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

The above sequence of functions will let you decrypt the majority of PDFs, however, for certain PDFs where the objects are stored in object streams -- and the PDF is encrypted -- then you need to use the SetAdvancePassword function to unlock the object streams so that the library can access the structure of the PDF and allow you to query it.

// Check the result of LoadFromFile, if the result 
// is 2, then you need to use SetAdvancePassword

int TestOpen = QP.LoadFromFile("encrypted.pdf");

if (TestOpen == 2)
{
  // The file contains encrypted content streams
  // and needs a password
  QP.SetAdvancePassword(password);
  TestOpen = QP.LoadFromFile("encrypted.pdf");
}
if (TestOpen == 1)
{
  // PDF was opened successfully
  QP.SaveToFile("decrypted.pdf");
}

© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum