DynaPDF.FlattenAnnotOrField
---------------------------

Draws an annotation or form field on the current open page.

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

MBS( "DynaPDF.FlattenAnnotOrField"; PDF; Field ) 

**MBS**( **"DynaPDF.FlattenAnnotOrField";** /\* Draws an annotation or form field on the current open page. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Field**) /\* The field index or annotation index.  
Field name doesn't work.e.g. "FirstName" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |
| Field | The field index or annotation index.   Field name doesn't work. | "FirstName" |

### Result

Returns OK or error.

### Description

Draws an annotation or form field on the current open page.   
Form fields are annotations of type atWidget. The annotations of a page can be enumerated with [DynaPDF.GetPageAnnotation](DynaPDFGetPageAnnotation.md) and [DynaPDF.GetPageAnnotCount](DynaPDFGetPageAnnotCount.md).   
The annotation or form field is deleted from the page's annotation array after it was flattened. If the function succeeds the return value is OK. If the function fails the return value is an error message.   
See also [FlattenAnnotOrField](https://www.monkeybreadsoftware.com/DynaPDF-Manual/FlattenAnnotOrField.shtml) function in DynaPDF manual.

### Examples

Sets a text field and flatterns it

 # Gets passed PDF number, field name, value and an action (Flatten or empty)   
\#   
\# Get variables   
Set Variable \[ $pdf ; Value: GetValue ( Get ( ScriptParameter ) ; 1 ) \]   
Set Variable \[ $fieldname ; Value: GetValue ( Get ( ScriptParameter ) ; 2 ) \]   
Set Variable \[ $value ; Value: GetValue ( Get ( ScriptParameter ) ; 3 ) \]   
Set Variable \[ $action ; Value: GetValue ( Get ( ScriptParameter ) ; 4 ) \]   
\#   
\# Set text for the field   
Set Variable \[ $SetError ; Value: MBS ( "[DynaPDF.SetTextFieldValueEx](DynaPDFSetTextFieldValueEx.md)" ; $pdf ; $fieldname ; $value ) \]   
If \[ $action = "Flatten" \]   
 # query, which page the field is on, so we can edit that page, required for drawing  
 Set Variable \[ $page ; Value: MBS ( "[DynaPDF.GetField](DynaPDFGetField.md)"; $pdf ; $fieldname ; "page") \]   
 If \[ $page &gt; 0 \]   
 Set Variable \[ $EditError ; Value: MBS ( "[DynaPDF.EditPage](DynaPDFEditPage.md)"; $pdf ; $page ) \]   
 If \[ $EditError = "OK" \]   
 # We loop over the fields on the page to find the right one  
 Set Variable \[ $PageFieldCount ; Value: MBS ( "[DynaPDF.GetPageFieldCount](DynaPDFGetPageFieldCount.md)"; $pdf ) \]   
 Set Variable \[ $PageFieldIndex ; Value: 0 \]   
 Set Variable \[ $found ; Value: 0 \]   
 If \[ $PageFieldIndex &lt; $PageFieldCount \]   
 Loop  
 # check name  
 Set Variable \[ $Name ; Value: MBS ( "[DynaPDF.GetPageField](DynaPDFGetPageField.md)"; $pdf ; $PageFieldIndex ; "name" ) \]   
 If \[ $Name = $fieldname \]   
 # found the field to flatten  
 Set Variable \[ $FlattenError ; Value: MBS ("DynaPDF.FlattenAnnotOrField"; $pdf ; $PageFieldIndex ) \]   
 Set Variable \[ $found ; Value: 1 \]   
 Exit Loop If \[ 1 \]   
 End If  
 #   
 # next  
 Set Variable \[ $PageFieldIndex ; Value: $PageFieldIndex + 1 \]   
 Exit Loop If \[ $PageFieldIndex ≥ $PageFieldCount \]   
 End Loop  
 End If  
 Set Variable \[ $r ; Value: MBS ( "[DynaPDF.EndPage](DynaPDFEndPage.md)"; $PDF ; $page ) \]   
 If \[ not $found \]   
 Exit Script \[ Text Result: "Field not found!" \]   
 Else  
 Exit Script \[ Text Result: $FlattenError \]   
 End If  
 Else  
 Exit Script \[ Text Result: $EditError \]   
 End If  
 End If  
End If  
Exit Script \[ Text Result: $SetError \]  
### See also

- [DynaPDF.EditPage](DynaPDFEditPage.md)
- [DynaPDF.EndPage](DynaPDFEndPage.md)
- [DynaPDF.GetField](DynaPDFGetField.md)
- [DynaPDF.GetPageAnnotation](DynaPDFGetPageAnnotation.md)
- [DynaPDF.GetPageAnnotCount](DynaPDFGetPageAnnotCount.md)
- [DynaPDF.GetPageField](DynaPDFGetPageField.md)
- [DynaPDF.GetPageFieldCount](DynaPDFGetPageFieldCount.md)
- [DynaPDF.SetFieldFlags](DynaPDFSetFieldFlags.md)
- [DynaPDF.SetTextFieldValue](DynaPDFSetTextFieldValue.md)
- [DynaPDF.SetTextFieldValueEx](DynaPDFSetTextFieldValueEx.md)

### Release notes

- **Version 13.0**
    - Fixed problem passing field index to [DynaPDF.FlattenAnnotOrField](https://www.mbsplugins.eu/DynaPDFFlattenAnnotOrField.shtml) function.
- **Version 10.0**
    - Added [DynaPDF.FlattenAnnotOrField](https://www.mbsplugins.eu/DynaPDFFlattenAnnotOrField.shtml) function.

### Blog Entries

- [MBS FileMaker Plugin, version 12.6pr1](https://www.mbsplugins.de/archive/2022-12-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [New in the MBS FileMaker Plugin 10.0](https://www.mbsplugins.de/archive/2020-01-23/New_in_the_MBS_FileMaker_Plugi/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.0pr8](https://www.mbsplugins.de/archive/2020-01-11/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 9th January 2020 , last changed 18th November 2022

  
[DynaPDF.FindText](DynaPDFFindText.md) - [DynaPDF.FlattenAnnots](DynaPDFFlattenAnnots.md)

[HTML Version](DynaPDFFlattenAnnotOrField.shtml)