PDF - Replace
Declaration
<AMPDF ACTIVITY="replace" SESSION="text" SOURCE="text" PASSWORD="text (encrypted)" SAVETYPE="text (options)" DESTINATION="text" TEXT="text" REPLACE="text" REGEX="YES/NO" PAGE="number" OCCURRENCES="number" SETFONT="YES/NO" FONT="text (options)" SIZE="number" FORGROUNDCOLOR="text (options)" BACKGROUNDCOLOR="text (options)" />
Description
Finds and replaces a text string with another text string from single page or all pages of a PDF file.
Practical usage
Can be used as a means to update PDF files with new data.
Parameters
Resource
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Resource | --- | --- | --- | --- | Specifies the source of the PDF file. The available options are:
NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes. |
Session | Text | Yes, if Resource is set to Session | PDFSession1 | SESSION="mySession" | The existing session to associate with this activity. This parameter becomes active and is required if the Resource parameter is set to Session. |
Source PDF | Text | Yes, if Resource is set to File | (Empty) | SOURCE="C:\PDFFileName.pdf" | The PDF path and file name of where to replace pages. This parameter becomes active and is required if the Resource parameter is set to File. |
Password (optional) | Text | No | (Empty) | PASSWORD="encrypted" | The password required to open the PDF file (if required). |
On completion | Text (options) | Yes, if Resource is set to File | Save |
|
Specifies how changes to the PDF file are saved upon completion of this activity. The available
options are:
|
Destination PDF | Text | Yes, if On completion is set to Save As | (Empty) | DESTINATION="C:\PDFFileName.pdf" | The path and file name where the modified PDF file is stored. This parameter becomes active and is required if the On completion parameter is set to Save as. |
Criteria
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Find | Text | Yes | (Empty) | FIND="PDF Security" | The text string to search for in the PDF file. |
Replace with | Text | Yes | (Empty) | REPLACE="Fortra" | The text string to replace in the PDF file, if the text was found by way of the Find parameter. |
Use regular expression | Yes/No | No | No | REGEX="YES" | If selected, indicates that the value entered in the Find parameter is a regular expression. If disabled (default), the value is literal text. |
Advanced
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Maximum replacements (optional) | Number | No | (Empty) | OCCURRENCES="3" | The total number of text string occurrences found to replace with new text. |
Replace font |
Yes/No |
No | No | SETFONT="YES" | If selected, font details and background color are replaced with the criteria specified in the Font, Font size, Text color, and Background color parameters. Disabled by default. |
Font | Text (options) | Yes, if Replace font is set to YES | Segoe UI | FONT="Tahoma" | Specifies the font to use to replace the original font in the text string. |
Font size | Number | Yes, if Replace font is set to YES | 11 | SIZE="10" | Specifies the font size to use to replace the original font size in the text string. |
Text color | Text (options) | Yes, if Replace font is set to YES | Black | FOREGROUNDCOLOR="Cyan" | Specifies the font color to use to replace the original font color in the text string. |
Background color | Text (options) | Yes, if Replace font is set to YES | White | BACKGROUNDCOLOR="Red" | Specifies the background color to use to replace the original background color in the text string. |
Page
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Page range | --- | Yes | All | --- | Specifies the pages to find and replace the text string in the PDF file. The
available options are:
NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes. |
Page(s) | Text | Yes, if Page range is set to Page(s) | (Empty) | PAGE="1,3,5" | If enabled, specifies the pages to find and replace the text string in the PDF file. For a single page, enter the page number. Use a comma (,) to specify more than one page (for example, 1,3,5). Use a dash (-) to specify a range of pages (for example, 5-10). |
Example
NOTE:
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Description
This sample task finds and replaces text in an existing PDF file and then saves it using a different file name.
Copy
<AMPDF ACTIVITY="replace" SOURCE="C:\temp\myDocument.pdf" SAVETYPE="save_as" DESTINATION="C:\temp\myDocument_new.pdf" TEXT="extract" REPLACE="remove" PAGE="1-6" />