Frequently Asked Question:
Securing PDFs to either prevent editing or warn that have been edited
My application creates PDF certificates. I need to add in a layer of security so that either the document can not be edited or I add a digital signature to the document which I understand will produce a warning when opened in a PDF Viewer/Reader if it has been edited.
Is SignFile the only method of applying a digital signature, I would like to add the signature whilst creating the PDF?
Can someone please point me in the right direction to how I create a .pfx file.
You can either encrypt a PDF file with document permissions which will prevent users from being able to edit your PDF documents or you can apply a digital signature to see if anyone has edited the document. I've included sample code for both options below.
Encrypt a PDF with document restrictions
// 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
QP.Encrypt("locked_down", "", 1, EncPerm);
// Save the updated file to the output folder
QP.SaveToFile("secured.pdf");
Apply a digital signature
// Use the SignFile function to apply the digital signature.
// This function handles loading the file, signing it, and then
// saving it to disk.
QP.SignFile("sign_me.pdf", "", "Digital Signature Test", "signed.pdf", "qpl_test.pfx",
"testing", "A good reason", "Here", "Quick PDF Library");
As for how to create a PFX file, there is a Microsoft TechNet aricle which covers this:
Creating the Personal Information Exchange (PFX) Certificate