setEncryption
Enable encryption on an output PDF file.
setEncryption([in] LONG outputHandle, [in] int mode,
[in] BSTR ownerPassword, [in] BSTR userPassword,
[in] int permissions)
This function enables encryption on the output PDF file
This function must be called immediately after openOutput
, before
calling any other functions on this output handle. Encryption is
performed on the fly, i.e., objects are encrypted as they are written
to the output file.
The arguments are:
mode
= encryption mode - one of the following values:encrypt128BitRC4
: 128-bit RC4 encryption (PDF 1.4 and higher)encrypt128BitAES
: 128-bit AES encryption (PDF 1.5 and higher)
ownerPassword
= the password which will be required to change the PDF fileuserPassword
= the password which will be required to open the file for viewing; to allow anyone to open the file (subject to the permissions), setuserPassword
to an empty stringpermissions
= the permission bits - see below
pdf.encrypt128BitRC4
, etc.
The permission bits should start with xpdfSplicePermBase
(which sets reserved bits according to the PDF spec). By itself,
permBase
disables all permissions. You can then add bits
from the following list:
permPrint
: printingpermModify
: general modificationpermCopy
: copy/extract text and graphicspermAnnotate
: add annotationspermFormFill
: fill form fieldspermAccessibility
: extract text and graphics for accessibilitypermAssemble
: assemble the documentpermPrintHQ
: high-quality printing
Note that all of the permission bit constants are read-only properties
on the COM component, so you'll need to
use pdf.permBase
, pdf.permPrint
, etc.
VB6:
Dim out as Long
out = pdf.openOutput("c:/test/newfile.pdf", 1.4)
' set user password to an empty string, so anyone can open the file
' set permissions to allow printing and nothing else
pdf.setEncryption out, pdf.encrypt128BitRC4, "Secret", "", pdf.permBase + pdf.permPrint
VB.net:
Dim out as Long
out = pdf.openOutput("c:/test/newfile.pdf", 1.4)
' set user password to an empty string, so anyone can open the file
' set permissions to allow printing and nothing else
pdf.setEncryption(out, pdf.encrypt128BitRC4, "Secret", "", pdf.permBase + pdf.permPrint)