DynaPDF.FlattenAnnots
---------------------

Flatten annotations.

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

MBS( "DynaPDF.FlattenAnnots"; PDF; Flags ) 

**MBS**( **"DynaPDF.FlattenAnnots";** /\* Flatten annotations. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Flags**) /\* The flags as text or number.   
Default is None.   
Can be None, UseViewState, MarkupAnnots or both combined as VisibleMarkupAnnots.e.g. "UseViewState" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |
| Flags | The flags as text or number.    Default is None.    Can be None, UseViewState, MarkupAnnots or both combined as VisibleMarkupAnnots. | "UseViewState" |

### Result

Returns number or error message.

### Description

Flatten annotations.  
Draws all annotations according to the used flags on the corresponding pages and deletes the annotations when finish. The flatten flags can be combined. The flag MarkupAnnots causes that non-markup annotations will be left intact (all kind of link, sound, and file attach annotations).  
  
The function flattens only annotations which contain an appearance stream. The function does not create missing appearances on demand.  
  
If the function succeeds the return value is the number of annotations which are still in memory.  
  
By default all annotations which have an appearance stream and which have the print flag set are flattened. All annotations are deleted when the function returns with the exception of file attachment annotations. If you want to flatten the view state then set the flag affUseViewState.  
  
| Flag Name | Flag Number | Description |
|---|---|---|
| None | 0 | Printable annotations independent of type. |
| UseViewState | 1 | If set, annotations which are visible in a viewer become flattened. |
| MarkupAnnots | 2 | If set, markup annotations are flattened only. Link, Sound, or FileAttach annotations are no markup annotations. Such types will be left intact. |
| NonPDFA\_1 | 4 | If set, flatten all annotations which are not supported in PDF/A 1. |
| NonPDFA\_2 | 8 | If set, flatten all annotations which are not supported in PDF/A 2 or 3. |
| FormFields | 16 | If set, form fields will be flattened too. |
| UseFieldViewState | 32 | Meaningful only if affFormFields or affSigFields is set. If set, flatten the view state of form fields. Use the print state otherwise. |
| SigFields | 64 | Meaningful only if affFormFields is not set. If set, signature fields with an appearance stream will be flattened. |
| KeepLinkAnnots | 4096 | If set, link annotations will be kept. |
| KeepFileAttach | 8192 | If set, file attachment annotations will be kept. |
| KeepTextAnnots | 16384 | If set, text annotations will be kept. |
| KeepEmptySigFields | 32768 | If set, signature fields which are not already signed will be kept. |
| KeepUnsupportedAnnots | 65536 | If set, annotations whose appearance stream cannot be rebuild will be kept (3D, Movie, Redact, or RichMedia annotations, for example). |
| PreserveZOrder | 4194304 | If set, preserve the z-order under any circumstances. That means visible overlapping annotations or form fields will be flattened, regardless the type. |

See also [FlattenAnnots](https://www.monkeybreadsoftware.com/DynaPDF-Manual/FlattenAnnots.shtml) function in DynaPDF manual.

### Examples

Flatten annotations and form fields:

 # Initialize DynaPDF if needed   
If \[ MBS ("[DynaPDF.IsInitialized](DynaPDFIsInitialized.md)") ≠ 1 \]   
 Perform Script \[ Specified: From list ; “InitDynaPDF” ; Parameter: \]  
End If  
\#   
\# New PDF environemnt   
Set Variable \[ $pdf ; Value: MBS ("[DynaPDF.New](DynaPDFNew.md)") \]   
\# Load PDF from container   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.OpenPDFFromContainer](DynaPDFOpenPDFFromContainer.md)"; $pdf ; MyTable::Input PDF) \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.ImportPDFFile](DynaPDFImportPDFFile.md)"; $pdf ; 1) \]   
\# Flatten annotations   
Set Variable \[ $r ; Value: MBS ( "DynaPDF.FlattenAnnots"; $PDF ) \]   
\# and the form fields   
Set Variable \[ $r ; Value: MBS ( "[DynaPDF.FlattenForm](DynaPDFFlattenForm.md)"; $PDF ) \]   
\# Save   
Set Field \[ MyTable::Output PDF ; MBS ("[DynaPDF.Save](DynaPDFSave.md)"; $pdf ; "Merged.pdf") \]   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.Release](DynaPDFRelease.md)"; $pdf ) \]  
### See also

- [DynaPDF.FlattenForm](DynaPDFFlattenForm.md)
- [DynaPDF.ImportPDFFile](DynaPDFImportPDFFile.md)
- [DynaPDF.IsInitialized](DynaPDFIsInitialized.md)
- [DynaPDF.New](DynaPDFNew.md)
- [DynaPDF.OpenPDFFromContainer](DynaPDFOpenPDFFromContainer.md)
- [DynaPDF.Release](DynaPDFRelease.md)
- [DynaPDF.Save](DynaPDFSave.md)

### Release notes

- **Version 14.3**
    - Added KeepUnsupportedAnnots option for [DynaPDF.FlattenAnnots](https://www.mbsplugins.eu/DynaPDFFlattenAnnots.shtml) function.

### Example Databases

- [DynaPDF/Highlight Text](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Highlight%20Text.shtml#2ScriptAnchor_)
- [DynaPDF/Live Styled Text](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Live%20Styled%20Text.shtml#3ScriptAnchor_)

### Blog Entries

- [Neues MBS Plugin 14.3 für Claris FileMaker](https://www.mbsplugins.de/archive/2024-07-09/Neues_MBS_Plugin_143_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 14.3 for Claris FileMaker](https://www.mbsplugins.de/archive/2024-07-09/MBS_FileMaker_Plugin_143_for_C/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.3pr3](https://www.mbsplugins.de/archive/2024-06-14/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.2pr1](https://www.mbsplugins.de/archive/2014-04-02/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 14th June 2024

  
[DynaPDF.FlattenAnnotOrField](DynaPDFFlattenAnnotOrField.md) - [DynaPDF.FlattenForm](DynaPDFFlattenForm.md)

[HTML Version](DynaPDFFlattenAnnots.shtml)