DynaPDF.SaveAndSignFileExt
--------------------------

Saves and signs the current PDF.

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

MBS( "DynaPDF.SaveAndSignFileExt"; PDF; PKCS12 Reference { ; ContactInfo; Location; Reason; Signer; FileName; Preview } ) 

**MBS**( **"DynaPDF.SaveAndSignFileExt";** /\* Saves and signs the current PDF. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$PKCS12 Reference**; /\* The reference to the PKCS12.  
See PKCS12.ReadFromContainer or PKCS12.ReadFromFile to load a PKCS#12 file.e.g. $pkcs12 \*/   
**$ContactInfo**; /\* Optional; The contact info. \*/   
**$Location**; /\* Optional; Signers location string \*/   
**$Reason**; /\* Optional; Reason string. \*/   
**$Signer**; /\* Optional; Signers name string \*/   
**$FileName**; /\* Optional; The file name to be associated with the container value.  
The file name should include pdf file extension.e.g. "hello.pdf" \*/   
**$Preview**) /\* Optional; Whether to include a preview JPEG.   
Default is 1 for including one. Pass zero to disable preview.e.g. 1 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |  |
| PKCS12 Reference | The reference to the PKCS12.   See PKCS12.ReadFromContainer or PKCS12.ReadFromFile to load a PKCS#12 file. | $pkcs12 |  |
| ContactInfo | The contact info. |  | Optional |
| Location | Signers location string | $location | Optional |
| Reason | Reason string. | $reason | Optional |
| Signer | Signers name string | $signer | Optional |
| FileName | The file name to be associated with the container value.   The file name should include pdf file extension. | "hello.pdf" | Optional |
| Preview | Whether to include a preview JPEG.    Default is 1 for including one. Pass zero to disable preview. | 1 | Optional |

### Result

Returns PDF container, OK or error.

### Description

Saves and signs the current PDF.  
On success you either get back the PDF as container value (in memory PDF) or it returns OK after writing PDF to file (file based PDF).  
The plugin also renders a JPEG for preview and includes it within the container value (with DynaPDF Pro).  
  
Same as [DynaPDF.SaveAndSignFile](DynaPDFSaveAndSignFile.md), but the signing is done by MBS plugin itself instead of DynaPDF. You pass the PKCS#12 key and certificate by reference number. This way we can support more keys than DynaPDF directly, e.g. with 2048 or 4096 bits.  
  
See [Plugin.SetPreviewSize](PluginSetPreviewSize.md) to control size of preview picture.  
  
If you have an open page, we close it automatically for you before doing the import.  
See also [SaveAndSignFileExt](https://www.monkeybreadsoftware.com/DynaPDF-Manual/CloseAndSignFileExt.shtml) function in DynaPDF manual.

### Examples

Sign a PDF with PKCS#12 key:

 # Initialize DynaPDF if needed   
If \[ MBS ("[DynaPDF.IsInitialized](DynaPDFIsInitialized.md)") ≠ 1 \]   
 Perform Script \[ Specified: From list ; “InitDynaPDF” ; Parameter: \]  
End If  
\# New PDF   
Set Variable \[ $pdf ; Value: MBS ("[DynaPDF.New](DynaPDFNew.md)") \]   
\#   
\# output to file   
Set Variable \[ $destPath ; Value: MBS ("[Folders.UserDesktop](FoldersUserDesktop.md)") &amp; "/test.pdf" \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.OpenOutputFile](DynaPDFOpenOutputFile.md)"; $pdf ; $destPath ) \]   
\#   
\# Load PDF from container   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.OpenPDFFromContainer](DynaPDFOpenPDFFromContainer.md)"; $pdf ; Merge PDFs::InputPDF ) \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.ImportPDFFile](DynaPDFImportPDFFile.md)"; $pdf ; 1) \]   
\#   
\# or sign it on saving   
Set Variable \[ $pkey ; Value: MBS ( "PKCS12.ReadFromFile"; "/Users/cs/Desktop/test\_cert.pfx"; "123456" ) \]   
Set Field \[ Merge PDFs::MergeStatus ; MBS ("DynaPDF.SaveAndSignFileExt"; $pdf ; $pkey ; "Hello"; "World"; ""; ""; "Merged.pdf") \]   
\#   
\# cleanup   
Set Variable \[ $r ; Value: MBS ( "PKCS12.Release"; $pkey ) \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.Release](DynaPDFRelease.md)"; $pdf ) \]  
### See also

- [DynaPDF.New](DynaPDFNew.md)
- [DynaPDF.OpenOutputFile](DynaPDFOpenOutputFile.md)
- [DynaPDF.OpenPDFFromContainer](DynaPDFOpenPDFFromContainer.md)
- [DynaPDF.Release](DynaPDFRelease.md)
- [DynaPDF.SaveAndSignFileExt1](DynaPDFSaveAndSignFileExt1.md)
- [DynaPDF.SaveAndSignFileExt2](DynaPDFSaveAndSignFileExt2.md)
- [Folders.UserDesktop](FoldersUserDesktop.md)
- [PKCS12.ReadFromContainer](PKCS12ReadFromContainer.md)
- [PKCS12.ReadFromFile](PKCS12ReadFromFile.md)
- [Plugin.SetPreviewSize](PluginSetPreviewSize.md)

### Release notes

- **Version 13.4**
    - Added new parameter useDetached for [DynaPDF.SaveAndSignFileExt1](https://www.mbsplugins.eu/DynaPDFSaveAndSignFileExt1.shtml) function.
- **Version 13.1**
    - Added [DynaPDF.SaveAndSignFileExt1](https://www.mbsplugins.eu/DynaPDFSaveAndSignFileExt1.shtml) and [DynaPDF.SaveAndSignFileExt2](https://www.mbsplugins.eu/DynaPDFSaveAndSignFileExt2.shtml) functions to sign a PDF using external PKCS7 signature provider.
- **Version 11.5**
    - Fixed documentation for [DynaPDF.SaveAndSignFileExt](https://www.mbsplugins.eu/DynaPDFSaveAndSignFileExt.shtml) and added missing ContactInfo parameter.
- **Version 11.1**
    - Fixed bug in [DynaPDF.SaveAndSignFileExt](https://www.mbsplugins.eu/DynaPDFSaveAndSignFileExt.shtml) function.
- **Version 11.0**
    - Added [DynaPDF.SaveAndSignFileExt](https://www.mbsplugins.eu/DynaPDFSaveAndSignFileExt.shtml) function to sign PDF file with 2048 or 4096 bit key length.

### Blog Entries

- [MBS FileMaker Plugin, version 11.5pr1](https://www.mbsplugins.de/archive/2021-10-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.1pr1](https://www.mbsplugins.de/archive/2021-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 11.0](https://www.mbsplugins.de/archive/2021-01-26/New_in_MBS_FileMaker_Plugin_11/monkeybreadsoftware_blog_filemaker)
- [Neues MBS FileMaker Plugin 11.0](https://www.mbsplugins.de/archive/2021-01-19/Neues_MBS_FileMaker_Plugin_110/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 11.0 - More than 6400 Functions In One Plugin](https://www.mbsplugins.de/archive/2021-01-19/MBS_FileMaker_Plugin_110_-_Mor/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.0pr6](https://www.mbsplugins.de/archive/2021-01-09/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 8th January 2021 , last changed 25th September 2024

  
[DynaPDF.SaveAndSignFile](DynaPDFSaveAndSignFile.md) - [DynaPDF.SaveAndSignFileExt1](DynaPDFSaveAndSignFileExt1.md)

[HTML Version](DynaPDFSaveAndSignFileExt.shtml)