(2)PDF Encryption with ps2pdf
PDF Encryption is available with Ghostscript's macros ps2pdf. This
allows you to restrict the use of the final PDF file.
There are two revisions of the security handler:
- Revision 2: Revision 2 does not work with GS 8.145. It is intended to
be used with KeyLength equal to 40 bits and produces PDF 1.3 compliant
documents; that is, intended to be used with Adobe Acrobat 4.0;
- Revision 3: Revision 3 is able to use KeyLength up to 128 bits and
produces PDF 1.4 compliant documents; that is, intended to be used
with Adobe Acrobat 5.0.
6.3.1 Common Command Line Parameters
-sOwnerPassword Password allowing full non restrictive access to the
document. Mandatory to use PDF restrictions.
-sUserPassword Password needed for opening the document. This
parameter may be left empty.
-dEncryptionR Revision to use. May be either 2 or 3.
-dKeyLength Length of the encryption key. With revision 2, must be
equal to 40, with revision 3, should be equal to 128.6
-dPermissions Permissions to apply to the document. See description
below.
6.3.2 Revision 2
Document Security can be set with the Permissions flag. For
EncryptionR=2, subtract these values from -4 to disable an access.
4 = Print document
8 = Modify contents of document
16 = Copy text and graphics from document
32 = Add or modify text annotations
To allow printing and copying, but disable modifying the contents and
annotations, the value is -4-8-32 so use -dPermissions=-44. To enable
all, use -dPermissions=-4. To disable all, use -dPermissions=-64.
Command line
ps2pdf13 -sOwnerPassword=OWNER -sUserPassword=USER \
-dEncryptionR=2 -dKeyLength=40 \
-dPermissions=PERMISSIONS in.ps out.pdf
6.3.3 Revision 3
See [9, Table 3.15, p. 77] for full details of the user access
permission values.
4 = Print document (possibly not at the highest quality level,
depending on whether 2048 is also set)
8 = Modify contents of document, except as controlled by 32, 256 and
1024
16 = Copy text and graphics from document other than that controlled
by 512
32 = Add or modify text annotations, fill in interactive form fields,
and if 256 is set, create or modify interactive form fields
256 = Fill in existing interactive form fields, even if 32 is clear
512 = Extract text and graphics (in support of accessibility to
disabled users or for other purposes)
1024 = Assemble the document (insert, rotate, or delete pages and
create bookmarks or thumbnail images), even if 16 is clear
2048 = Print the document to a representation from which a faithful
digital copy of the PDF contents could be generated. When this is
clear (and 4 is set), printing is limited to a low-level
representation of the appearance, possibly of degraded quality.
To enable all, use -dPermissions=-4. To disable everything apart from
viewing, combine the following -4 (base) -4 (print) -8 (modify) -16
(copy) -32 (annotate) -256 (interactive fields) -512 (copy for
disability access) -1024 (assemble) -2048 (high quality print), so
-dPermisions=-3904.
Command line :
ps2pdf14 -sOwnerPassword=OWNER -sUserPassword=USER \
-dEncryptionR=3 -dKeyLength=128 \
-dPermissions=PERMISSIONS in.ps out.pdf