replaceTokens
Replaces all occurrences of a specified text string from a stored PDF file and saves the resulting PDF file in the file upload location.
Syntax
function replaceTokens(sourceRealName: string, destinationName: string, searchText: string, replacementText: string, textOptions: any): string
| Parameter | Description |
|---|---|
sourceRealName
|
Unique internal ID of the source PDF file (real name). |
destinationName
|
File name assigned to the resulting PDF. |
searchText
|
Text string to be replaced. |
replacementText
|
Text string to replace with. |
textOptions
|
Optional JSON object for text formatting:{'fontColor' : string, 'fontName' : string, 'fontSize': number} |
IMPORTANT!
Use the backslash (\) escape character before any special characters you wish to include in your text strings (\\, \', \" etc).
Use the backslash (\) escape character before any special characters you wish to include in your text strings (\\, \', \" etc).
Return Value
Returns a string containing the resulting PDF's real name.
Examples
In this example:
- We update the CTR_offer_fec96615-7608-4fd5-9916-6e5596c523eb.pdf file by replacing the Computing-Tabulating-Recording Company text string with the International Business Machines replacement text.
- We save the resulting document in a file called IBM_offer.pdf.
- We save the real name of the extracted file in a variable called message.
- We display the message variable on screen. For details on how to display messages, see setMessage.
message = replaceTokens('CTR_offer_fec96615-7608-4fd5-9916-6e5596c523eb.pdf', 'IBM_offer', 'Computing-Tabulating-Recording Company', 'International Business Machines');
setMessage(message);