DynaPDF.ReplacePattern
----------------------

Replaces a text with a new text.

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

MBS( "DynaPDF.ReplacePattern"; PDF; Text; NewText { ; Alignment; NewFontSize; NewFontStyle; NewCharacterSpacing; NewTextScaling; NewTextRise; NewTextColor } ) 

**MBS**( **"DynaPDF.ReplacePattern";** /\* Replaces a text with a new text. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Text**; /\* The text to search.e.g. "Hello" \*/   
**$NewText**; /\* The text to replace the found location with.e.g. "World" \*/   
**$Alignment**; /\* Optional; The new alignment you want. 0 = Left, 1 = Center and 2 = Right. May not work with rotated text.e.g. 0 \*/   
**$NewFontSize**; /\* Optional; The new font size to use. Use -1 to keep whatever it is. Due to matrix scaling in pdf, the size here may be far off. \*/   
**$NewFontStyle**; /\* Optional; The new font style. Use -1 to keep whatever it is. e.g. 4 for underline, 2 for bold, 1 for italic or a combination. See dynapdf manual for more values for font styles.e.g. 0 \*/   
**$NewCharacterSpacing**; /\* Optional; The new character spacing value. See also [DynaPDF.SetCharacterSpacing](DynaPDFSetCharacterSpacing.md).  
If undefined, keeps current character spacing.e.g. 2 \*/   
**$NewTextScaling**; /\* Optional; The text scaling to use. \*/   
**$NewTextRise**; /\* Optional; The text rise to use.   
In percent of text height as plugin multipies y by given factor. \*/   
**$NewTextColor**) /\* Optional; The new stroke &amp; fill color.  
Pass negative number to keep existing color.e.g. MBS( "DynaPDF.RGB"; 0; 0; 255 ) \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |  |
| Text | The text to search. | "Hello" |  |
| NewText | The text to replace the found location with. | "World" |  |
| Alignment | The new alignment you want. 0 = Left, 1 = Center and 2 = Right. May not work with rotated text. | 0 | Optional |
| NewFontSize | The new font size to use. Use -1 to keep whatever it is. Due to matrix scaling in pdf, the size here may be far off. |  | Optional |
| NewFontStyle | The new font style. Use -1 to keep whatever it is. e.g. 4 for underline, 2 for bold, 1 for italic or a combination. See dynapdf manual for more values for font styles. | 0 | Optional |
| NewCharacterSpacing | The new character spacing value. See also [DynaPDF.SetCharacterSpacing](DynaPDFSetCharacterSpacing.md).   If undefined, keeps current character spacing. | 2 | Optional |
| NewTextScaling | The text scaling to use. |  | Optional |
| NewTextRise | The text rise to use.    In percent of text height as plugin multipies y by given factor. |  | Optional |
| NewTextColor | The new stroke &amp; fill color.   Pass negative number to keep existing color. | MBS( "DynaPDF.RGB"; 0; 0; 255 ) | Optional      Added in version **9.1**. |

### Result

Returns number of locations found.

### Description

Replaces a text with a new text.  
You need to have an open page. you can use [DynaPDF.EditPage](DynaPDFEditPage.md) to edit an existing one.  
Needs DynaPDF Pro license.  
  
The replace pattern function is great to replace small place holder with real values in a text. But it doesn't do much formatting except parameters below and won't work with multi line texts. For bigger texts, please consider drawing a white rectangle and then use [DynaPDF.WriteStyledText](DynaPDFWriteStyledText.md) or similar functions to draw text on top.  
  
See also newer functions [DynaPDF.Parser.FindText](DynaPDFParserFindText.md) and [DynaPDF.Parser.ReplaceSelText](DynaPDFParserReplaceSelText.md).  
### Examples

Replace placeholder with text:

 MBS ("DynaPDF.ReplacePattern"; $pdf ; "&lt;&lt;PLZ Ort&gt;&gt;"; "56645 Nickenich")  
Replace some texts with different alignment:

 Set Variable \[ $r1 ; Value: MBS ("DynaPDF.ReplacePattern"; $pdf ; "Hello1"; "Hello World"; 0) \]   
Set Variable \[ $r2 ; Value: MBS ("DynaPDF.ReplacePattern"; $pdf ; "Hello3"; "Hello World"; 1) \]   
Set Variable \[ $r3 ; Value: MBS ("DynaPDF.ReplacePattern"; $pdf ; "Hello5"; "Hello World"; 2) \]  
Replace text, make it centered and underlined:

 MBS ("DynaPDF.ReplacePattern"; $pdf ; "Hello3"; "Hello World"; 1; -1; 4)  
### See also

- [DynaPDF.EditPage](DynaPDFEditPage.md)
- [DynaPDF.Initialize](DynaPDFInitialize.md)
- [DynaPDF.New](DynaPDFNew.md)
- [DynaPDF.Parser.FindText](DynaPDFParserFindText.md)
- [DynaPDF.Parser.ReplaceSelText](DynaPDFParserReplaceSelText.md)
- [DynaPDF.RGB](DynaPDFRGB.md)
- [DynaPDF.SetCharacterSpacing](DynaPDFSetCharacterSpacing.md)
- [DynaPDF.WriteStyledText](DynaPDFWriteStyledText.md)

### Release notes

- **Version 12.2**
    - Changed [DynaPDF.ReplacePattern](https://www.mbsplugins.eu/DynaPDFReplacePattern.shtml) to fallback to Courier (fixed pitch), Times (serif) or Helvetica as font.
- **Version 9.3**
    - Fixed a problem with [DynaPDF.ReplacePattern](http://www.mbsplugins.eu/DynaPDFReplacePattern.shtml) function and fonts missing the CID Ordering table.
- **Version 9.1**
    - Added NewTextColor parameter for [DynaPDF.ReplacePattern](http://www.mbsplugins.eu/DynaPDFReplacePattern.shtml) function.
- **Version 8.3**
    - Fixed bug in [DynaPDF.ReplacePattern](http://www.mbsplugins.eu/DynaPDFReplacePattern.shtml) when new text was added behind existing text instead before.

### Example Databases

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

### Blog Entries

- [MBS Plugin 12.2 for Claris FileMaker](https://www.mbsplugins.de/archive/2022-05-17/MBS_Plugin_122_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.2pr1](https://www.mbsplugins.de/archive/2022-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.3pr1](https://www.mbsplugins.de/archive/2019-06-03/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 9.1 - More than 5700 Functions In One Plugin](https://www.mbsplugins.de/archive/2019-03-12/MBS_FileMaker_Plugin_91_-_More/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.1pr2](https://www.mbsplugins.de/archive/2019-02-11/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.3pr2](https://www.mbsplugins.de/archive/2018-06-18/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.5pr6](https://www.mbsplugins.de/archive/2016-11-08/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.5pr4](https://www.mbsplugins.de/archive/2015-12-28/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.2pr1](https://www.mbsplugins.de/archive/2015-06-01/MBS_FileMaker_Plugin_version_5/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 25th February 2026

  
[DynaPDF.ReplaceImage](DynaPDFReplaceImage.md) - [DynaPDF.ResetAnnotAP](DynaPDFResetAnnotAP.md)

[HTML Version](DynaPDFReplacePattern.shtml)