<< back to the Securely main page

BenCoding.Securely.PDF

The Securely PDF module is used to lock and unlock PDF files. Please note this is an iOS specific module.

Getting Started


var securely = require('bencoding.securely');

Requiring Securely into your project

Requiring the module into your project


//Require the securely module into your project
var securely = require('bencoding.securely');

Creating the PDF Object

The following demonstrates how to create a new instance of the Securely PDF component.


var pdf = securely.createPDF();

Methods

protect

( Dictionary options ) Creates a new password protected PDF using an existing unprotected PDF.

Parameters

The protected method takes a dictionary with the following options:

userPassword - User level password to lock the PDF with

ownerPassword - Owner level password to lock the PDF with

from - The path for an existing unlocked PDF to be used as the source to create a new locked PDF

to - The output path for a new locked PDF to be created using the source PDF provided in the from parameter

allowCopy - (true/false) if the locked PDF should allow for copying

allowPrint - (true/false) if the locked PDF should allow for printing

completed - The callback method that will be called after the locked PDF is created.

Example


function onProtected(e){
  //Print full statement to the console
    Ti.API.info(JSON.stringify(e));
};

var inputFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'my.pdf');
var outputFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'myLocked.pdf');

pdf.protect({ userPassword:"your_password", ownerPassword:"your_password", from:inputFile.nativePath, to:outputFile.nativePath, allowCopy:false, allowPrint:true, completed:onProtected });


unprotect

( Dictionary options ) Creates a new unlocked PDF from an existing locked PDF document.

Parameters The unprotect method takes a dictionary with the following options:

password - Owner level password to unlock the PDF

from - The path for an existing password protected PDF to be used as the source to create a new unlocked PDF

to - The output path for a new unlocked PDF to be created using the source PDF provided in the from parameter

completed - The callback method that will be called after the unlocked PDF is created.

Example


function onUnlock(e){
  //Print full statement to the console
    Ti.API.info(JSON.stringify(e));
};

var protectedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'myLocked.pdf'), unlockedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'myUnlocked.pdf');

pdf.unprotect({ password:txtPassword.value, from:protectedFile.nativePath, to:unlockedFile.nativePath, completed:onUnlock });