40
PDF Security
PDF provides a variety of different security options. From a simple open password -- where the
user must type in a password prior to being able to view the PDF -- to the more complicated
options where a master password can be used to apply document restrictions, such as no
printing, no editing, etc, to the document. It is also possible to apply digital signatures to PDF
files.
There are two different types of passwords used in PDF files but also two different terms for
each of these types: an owner or master password and an open or user password. The owner
or master password is required for setting document restrictions and the open or user password
is required for making the user enter in a password prior to viewing the document.
Open password
If you want to require that the user type in a password prior to being able to view the PDF file
then you need to encrypt the PDF with an open password.
/* Apply an open password to a PDF */
// Load a sample file from the input folder
QP.LoadFromFile("secure_me.pdf", “”);
// For adding document restrictions we'll use the
// EncodePermissions function. For this example we will
// not restrict any actions.
EncPerm = QP.EncodePermissions(1, 1, 1, 1, 1, 1, 1, 1);
// Encrypting the document must be the last
// function called prior to saving
QP.Encrypt("locked_down", "", 1, EncPerm);
// Save the updated file to the output folder
QP.SaveToFile("secured.pdf");
Document restrictions
If you want to prevent the user from performing certain actions with your document then you
need to add document restrictions to your PDF along with an owner password.
/* Apply a master document and document restrictions to a PDF */
// Load a sample file from the input folder
QP.LoadFromFile("secure_me.pdf", “”);
// For adding document restrictions we'll use the
// EncodePermissions function. Look at this function
// in the reference to see what the available options are.
// In this sample the only permission we'll give the user
// to the ability to print the document. The user won't be
// able to copy text, modify the document, etc.
EncPerm = QP.EncodePermissions(1, 0, 0, 0, 0, 0, 0, 0);
// Encrypting the document must be the last
// function called prior to saving