Add password security to PDF

Post Reply
JHDietz
Newbie
Posts: 3
Joined: Fri Mar 16, 2012 1:17 pm

Add password security to PDF

Post by JHDietz »

I'm looking for a way to add password security to a PDF. It is going to be used for proof PDF files for customers. They are not allowed to print the PDF or change it in any way.



Does anybody have a workflow/script for that? Thanks in advance!
Clive Andrews
Member
Posts: 85
Joined: Thu Jun 23, 2011 11:41 am

Add password security to PDF

Post by Clive Andrews »

You can use CPDF to do it, likewise, you can add a "proof" watermark... http://www.coherentpdf.com/



Encryption is page 13 of the user guide:



4.1 Introduction

PDF files can be encrypted using various types of encryption and attaching various permissions

describing what someone can do with a particular document (for instance, printing it

or extracting content). There are two types of person:

The User can do to the document what is allowed in the permissions.

The Owner can do anything, including altering the permissions.

There are three kinds of encryption: 40-bit encryption (method 40bit) in Acrobat 3 (PDF

1.1) and above, 128-bit encryption (method 128bit) in Acrobat 5 (PDF 1.4) and above, and

AES encryption (method AES) in Acrobat 7 (PDF 1.6) and above.

All encryption supports these kinds of permissions:

-no-edit Cannot change the document

-no-print Cannot print the document

-no-copy Cannot select or copy text or graphics

-no-annot Cannot add or change form fields or annotations

In addition, 128-bit encryption (Acrobat 5 and above) and AES encryption supports these:

-no-forms Cannot edit form fields

-no-extract Cannot extract text or graphics

-no-assemble Cannot merge files etc.

-no-hq-print Cannot print high-quality

Add these flags to the command line to prevent each operation.
JHDietz
Newbie
Posts: 3
Joined: Fri Mar 16, 2012 1:17 pm

Add password security to PDF

Post by JHDietz »

Thanks Clive for your quick response, I will look into it! It sounds like a perfect solution to the problem.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Add password security to PDF

Post by dkelly »

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
JHDietz
Newbie
Posts: 3
Joined: Fri Mar 16, 2012 1:17 pm

Add password security to PDF

Post by JHDietz »

Thank you Dwight for your solution, i will try it!
KaesDS
Newbie
Posts: 12
Joined: Thu Sep 22, 2016 10:33 am

Re: Add password security to PDF

Post by KaesDS »

Hello Dwight,

your solution works great so far but i need to fully restrict the PDF from opening it.

I already checked the QPDF manual but with very little success.

Is it possible to prevent the PDF from being opened with a password like the manual way in Adobe Acrobat?
Malcolm Mackenzie
Member
Posts: 121
Joined: Wed Mar 22, 2017 5:05 pm
Location: London, UK
Contact:

Re: Add password security to PDF

Post by Malcolm Mackenzie »

Hi
PDFtk should be able to do it using CLI
https://www.pdflabs.com/docs/pdftk-cli-examples/
Encrypt a PDF using 128-bit strength (the default), withhold all permissions (the default)
pdftk 1.pdf output 1.128.pdf owner_pw foopass
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

Re: Add password security to PDF

Post by abonsey »

pdftk does the trick

We do this for client files.

Try installing pdftk.exe
The run the Execute Command using within the flow:

"%1" output "%2" user_pw XXXXX
File at Path
Copy Input Job = No
Output Extension = Automatic
Disregard Exit Code
KaesDS
Newbie
Posts: 12
Joined: Thu Sep 22, 2016 10:33 am

Re: Add password security to PDF

Post by KaesDS »

Thanks both of you! It works like a charm! :D
Post Reply