Crionics LOGO

TUTORIALS

 

 How to change permissions or credentials

As easy as 1, 2, 3...

 

Open the document you wish to change


In this tutorial we are going to change the permissions and the credentials of a ciphered document. This tutorial may also be used to uncipher documents. The tutorial assumes that you already have significant knowledge about the jPDF Encryption Module.

First, we need to create author privileges for the document. Only the author of the document can perform such modifications.

PDF security considers the document as a whole: it is not possible for a document to use multiple cipher methods. This is particulary important when the document needs to be changed as it means the whole file needs to be processed and re-ciphered.

But let's start with some code:

// Open the protected document using the author password:
PasswordCredentials openCredentials = new PasswordCredentials("authorPassword");
PdfDocument docSrc= new PdfDocument("MyCipheredDocument.pdf", openCredentials );
If the document uses Certificate Security, please refer to the appropriate tutorial to open it.

 

Pick the new privileges and encryption settings

Select passwords and encryption key length.

// Create the object containing all the new permissions:
Preferences preferences = new Preferences();

// Change the permissions to your likings:
Permissions permissions = new Permissions();
permissions.setDenyAll();
permissions.setCanPrint(true);
permissions.setPrintQuality(Permissions.QUALITY_HIGH);

// Create the credentials - using Password or Certificate Security:
PasswordCredentialsCreation credentials = new PasswordCredentialsCreation("myNewAdminPw", "reader", permissions);
preferences.setDefaultCredentials(credentials);

 

Process and save the new document

Now that all the settings are in place, we need only process the document. (Note that even if PDF supports incremental updates, it is not possible to have a document use different encryption types: the whole document must use the same settings. For this reason, when you change credentials or permissions, the whole file needs to be reprocessed.)

// Create the encrypted document:
document.getEncryptionModule().processTo(dst, preferences);

// Close the original document:
document.close();


© 2000-2007 Crionics Inc. Report issues with this page