We just released a new endpoint to the ReportingCloud Web API:
https://api.reporting.cloud/v1/document/findandreplace
This new endpoint can be used to find any text in any text part of a document including the main text, headers and footers and text frames. The endpoint POST method accepts an array of string arrays with pair values to find and replace strings in a template.
The following code, that uses the ReportingCloud .NET wrapper, finds and replaces the string Invoice with ReplacedText and Invoice2 with ReplacedText2 in the complete document.
ReportingCloud rc = new ReportingCloud("username", "password"); | |
FindAndReplaceBody body = new FindAndReplaceBody(); | |
body.FindAndReplaceData = new List<string[]> { | |
new string[] { "Invoice", "ReplacedText" }, | |
new string[] { "Invoice2", "ReplacedText2" } | |
}; | |
byte[] bDocument = rc.FindAndReplaceDocument(body, "invoice.tx", ReturnFormat.HTML); | |
string sHtmlDocument = System.Text.Encoding.UTF8.GetString(bDocument); | |
Console.WriteLine(sHtmlDocument.Contains("ReplacedText")); |
For mail merge purposes, usually merge fields are used and those templates are merged using the endpoint document/merge. But in several scenarios or templates from legacy applications, simple find and replace processes are very useful.
Start today with ReportingCloud and sign up for a free trial account.
Happy coding!