Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

DynaPDF.EnableEncryption

Enables encryption for next save command.

Component Version macOS Windows Linux Server iOS SDK
DynaPDF 3.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "DynaPDF.EnableEncryption"; PDF; OpenPwd; OwnerPwd; Encryption { ; RestrictFlags } )   More

Parameters

Parameter Description Example Flags
PDF The PDF reference returned from DynaPDF.New. $pdf
OpenPwd Open password. ""
OwnerPwd Owner password. "Hello"
Encryption Which encryption to use. Can be 40bit, 128bit, 128bitEx, AES128, AES256 or AESRev6. "AES256"
RestrictFlags What restrictions to apply. See above. 4+8 Optional

Result

Returns OK on success.

Description

Enables encryption for next save command.

Available Encryption methods:
IDEncryptionPDF VersionAcrobat Version
0RC4 40bitPDF 1.2Acrobat 3 or higher
1RC4 128bitPDF 1.4Acrobat 5 or higher
2RC4 128bit improvedPDF 1.5Acrobat 6 or higher
3AES 128bitPDF 1.6Acrobat 7 or higher
4AES 256bitPDF 1.7Acrobat 9 or higher

Available restrictions:
DenyNothing0Encrypt the file only
DenyAll3900Deny anything
Print4Deny printing
Modify8Deny modification of contents
CopyObj16Deny copying of contents
AddObj32No commenting
FillInFormFields256requires Modify + AddObj
ExtractObj512requires Modify
Assemble1024requires Modify
PrintHighRes2048Disable high res. printing
ExlMetadata4096PDF 1.5 Exclude metadata streams
EmbFilesOnly8192PDF 1.6 AES Encryption only

FillInFormFields and later are for 128/256 bit encryption only, so ignored if 40 bit encryption is used.
Please combine those like this: Print and Modify = 4 + 8 = 12.
Please see DynaPDF help on CloseFileEx function for details on which combination of restrictions are possible.
For passwords, please use only ASCII characters to avoid trouble with text encodings.

Requires DynaPDF Lite license. See CloseAndSignFile in the dynapdf help, since that function will be used later by DynaPDF.Save function.

See also EnableEncryption function in DynaPDF manual.

Examples

Don't allow adding content:

MBS( "DynaPDF.EnableEncryption"; $PDF; ""; "secret"; 1; 16 + 32 + 256 + 1024 )

Create AES 256-bit encrypted PDF:

# Initialize DynaPDF if needed
If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
    Perform Script [ Specified: From list ; “InitDynaPDF” ; Parameter: ]
End If
# Clear current PDF document
Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ]
# Add page
Set Variable [ $r ; Value: MBS("DynaPDF.AppendPage"; $pdf) ]
# Write some text
Set Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "Helvetica"; 0; 12) ]
Set Variable [ $x ; Value: MBS("DynaPDF.GetPageHeight"; $pdf)-100 ]
Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; 0; 0; 0) ]
Set Variable [ $r ; Value: MBS("DynaPDF.WriteText"; $pdf; 100; $x; "Some black text") ]
# End page
Set Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ]
# Add encryption with AES
Set Variable [ $r ; Value: MBS( "DynaPDF.EnableEncryption"; $PDF; "xxx"; "yyy"; "AES256"; 8+16+32+256+512+1024+2048+4096 ) ]
# Save PDF to put in container later
Set Variable [ $PDFData ; Value: MBS("DynaPDF.Save"; $pdf; "hello.pdf") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]
# Put in Container
Set Field [ Create Text::PDF ; $PDFData ]

See also

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 28th May 2024


DynaPDF.Ellipse - DynaPDF.EnableImageCache