DynaPDF.EnableEncryption
------------------------

Enables encryption for next save command.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [DynaPDF](component_DynaPDF.md) | [3.4](newinversion34.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "DynaPDF.EnableEncryption"; PDF; OpenPwd; OwnerPwd; Encryption { ; RestrictFlags } ) 

**MBS**( **"DynaPDF.EnableEncryption";** /\* Enables encryption for next save command. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$OpenPwd**; /\* Open password.e.g. "" \*/   
**$OwnerPwd**; /\* Owner password.e.g. "Hello" \*/   
**$Encryption**; /\* Which encryption to use. Can be 40bit, 128bit, 128bitEx, AES128, AES256 or AESRev6.e.g. "AES256" \*/   
**$RestrictFlags**) /\* Optional; What restrictions to apply. See above.e.g. 4+8 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $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:  
| ID | Encryption | PDF Version | Acrobat Version |
|---|---|---|---|
| 0 | RC4 40bit | PDF 1.2 | Acrobat 3 or higher |
| 1 | RC4 128bit | PDF 1.4 | Acrobat 5 or higher |
| 2 | RC4 128bit improved | PDF 1.5 | Acrobat 6 or higher |
| 3 | AES 128bit | PDF 1.6 | Acrobat 7 or higher |
| 4 | AES 256bit | PDF 1.7 | Acrobat 9 or higher |

  
Available restrictions:  
| DenyNothing | 0 | Encrypt the file only |
|---|--:|---|
| DenyAll | 3900 | Deny anything |
| Print | 4 | Deny printing |
| Modify | 8 | Deny modification of contents |
| CopyObj | 16 | Deny copying of contents |
| AddObj | 32 | No commenting |
| FillInFormFields | 256 | requires Modify + AddObj |
| ExtractObj | 512 | requires Modify |
| Assemble | 1024 | requires Modify |
| PrintHighRes | 2048 | Disable high res. printing |
| ExlMetadata | 4096 | PDF 1.5 Exclude metadata streams |
| EmbFilesOnly | 8192 | PDF 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](DynaPDFSave.md) function.  
See also [EnableEncryption](https://www.monkeybreadsoftware.com/DynaPDF-Manual/OpenOutputFileEncrypted.shtml) 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](DynaPDFIsInitialized.md)") ≠ 1 \]   
 Perform Script \[ Specified: From list ; “InitDynaPDF” ; Parameter: \]  
End If  
\# Clear current PDF document   
Set Variable \[ $pdf ; Value: MBS ("[DynaPDF.New](DynaPDFNew.md)") \]   
\# Add page   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.AppendPage](DynaPDFAppendPage.md)"; $pdf ) \]   
\# Write some text   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.SetFont](DynaPDFSetFont.md)"; $pdf ; "Helvetica"; 0; 12) \]   
Set Variable \[ $x ; Value: MBS ("[DynaPDF.GetPageHeight](DynaPDFGetPageHeight.md)"; $pdf )-100 \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.SetFillColor](DynaPDFSetFillColor.md)"; $pdf ; 0; 0; 0) \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.WriteText](DynaPDFWriteText.md)"; $pdf ; 100; $x ; "Some black text") \]   
\# End page   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.EndPage](DynaPDFEndPage.md)"; $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](DynaPDFSave.md)"; $pdf ; "hello.pdf") \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.Release](DynaPDFRelease.md)"; $pdf ) \]   
\# Put in Container   
Set Field \[ Create Text::PDF ; $PDFData \]  
### See also

- [DynaPDF.AppendPage](DynaPDFAppendPage.md)
- [DynaPDF.GetPageHeight](DynaPDFGetPageHeight.md)
- [DynaPDF.GetUserRights](DynaPDFGetUserRights.md)
- [DynaPDF.IsInitialized](DynaPDFIsInitialized.md)
- [DynaPDF.New](DynaPDFNew.md)
- [DynaPDF.Release](DynaPDFRelease.md)
- [DynaPDF.Save](DynaPDFSave.md)
- [DynaPDF.SetFillColor](DynaPDFSetFillColor.md)
- [DynaPDF.SetFont](DynaPDFSetFont.md)
- [DynaPDF.WriteText](DynaPDFWriteText.md)

### Blog Entries

- [Unlocking the Power of PDFs in FileMaker with DynaPDF and the MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2024-09-16/Unlocking_the_Power_of_PDFs_in/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 3.4pr2](https://www.mbsplugins.de/archive/2013-08-28/MBS_Filemaker_Plugin_version_3/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[DynaPDF.Ellipse](DynaPDFEllipse.md) - [DynaPDF.EnableImageCache](DynaPDFEnableImageCache.md)

[HTML Version](DynaPDFEnableEncryption.shtml)