Here's a free solution I developed using qpdf (
http://qpdf.sourceforge.net)
// Encrypt/Decrypt PDF files using qpdf
//
// Written by Dwight Kelly <
dkelly@apago.com>
// Copyright 2012 by Apago, Inc. -- All Rights Reserved
function jobArrived( s : Switch, job : Job )
{
var appPath = "/opt/local/bin/qpdf";
var String args = new Array();
var argc = 0;
args[argc++] = appPath;
if (s.getPropertyValue("encrypt") == "Yes") {
args[argc++] = "--encrypt";
args[argc++] = ""; // no user (open) password
args[argc++] = s.getPropertyValue("password"); // owner password
args[argc++] = "128";
args[argc++] = "--use-aes=y"; // 128-bit AES
args[argc++] = "--print=full"; // permissions
args[argc++] = "--modify=annotate";
args[argc++] = "--extract=n";
args[argc++] = "--";
} else {
args[argc++] = "--decrypt";
args[argc++] = "--password=" + s.getPropertyValue("password");
}
args[argc++] = job.getPath();
var String outFile = job.createPathWithName(job.getName()); // output file
args[argc++] = outFile;
var exitStatus = Process.execute(args);
var pdfFile = new File(outFile);
if (exitStatus == 0 && pdfFile.exists) {
// success
job.sendToSingle( outFile, job.getName() );
return;
}
// failure
job.fail("qpdf failed, errcode:" + exitStatus );
}
Learn advanced Javascript for Switch
Full day seminar during Graph Expo in Chicago, Oct 8th, 2012
http://www.brownpapertickets.com/event/264833
Dwight Kelly
Apago, Inc.
dkelly@apago.com