.NET
TXTextControl.ReportingCloud is the NuGet package that calls the ReportingCloud Web API from C#. Its ReportingCloud class has a method for each endpoint, those of the two tracked-changes endpoints in its property Processing.Review: you pass .NET objects and byte arrays, and the class sends the JSON request, checks the answer and returns the documents as byte arrays. Below are the package's target frameworks, how the class authenticates, a merge example and every method with the endpoint it calls.
For a first application built step by step, follow ASP.NET Core or .NET Framework in Getting Started.
Package and Requirements
| Package | Version | Released | Target frameworks | Dependencies |
|---|---|---|---|---|
| TXTextControl.ReportingCloud | 1.205.500 | September 2, 2019 | .NET Framework 4.5, .NET Standard 1.3, .NET Core 1.1 | Newtonsoft.Json 10.0.3 or later, and per target framework Microsoft.AspNet.WebApi 5.2.6, NETStandard.Library 1.6.1 or Microsoft.NETCore.App 1.1.2 |
The package holds one assembly, ReportingCloudWrapper.dll, for each target framework, and its classes are in the namespace TXTextControl.ReportingCloud. A project for .NET 8 or .NET 10 gets the .NET Core 1.1 build: a .NET 10 console application compiles and runs with it. Restoring the package in a .NET 10 project reports warning NU1903, a dependency with a known vulnerability, for Newtonsoft.Json 10.0.3, Microsoft.NETCore.App 1.1.2 and Microsoft.NETCore.Jit 1.1.2. Installing an SDK explains what you can do about them, shows the other ways to install the package and checks the installation with a first call.
Install the package with the .NET CLI in the folder of your project:
dotnet add package TXTextControl.ReportingCloud
The package TXTextControl.ReportingCloud.Core was a separate build for .NET Core until the multi-target package replaced it, as the blog article ReportingCloud: One Multi-Target Wrapper for .NET, .NET Core and .NET Standard announced. Its last version, 1.200.500 of November 30, 2018, describes itself as deprecated: don't use it in new projects.
Authentication
Every method runs on an instance of ReportingCloud. Its constructor takes the credentials that the class sends with each request:
| Constructor | Authorization header of every request |
|---|---|
ReportingCloud(string apikey) | ReportingCloud-APIKey followed by the key |
ReportingCloud(string apikey, Uri webApiBaseUrl) | The same, sent to another base URL |
ReportingCloud(string username, string password) | Basic followed by the Base64-encoded user name and password |
ReportingCloud(string username, string password, Uri webApiBaseUrl) | The same, sent to another base URL |
Without webApiBaseUrl, the requests go to https://api.reporting.cloud. The properties APIKey, Username, Password and WebApiBaseUrl change the values later. When APIKey holds a key, the class sends it and ignores the user name and password. Use an API key: API Keys shows how to create one, and Authentication explains both methods.
Merge a Template
The following console application merges sample_invoice.tx, the demo template in the template storage of every trial account, with one invoice record and saves the result as invoice.pdf. Create it with dotnet new console, add the package, set the environment variable REPORTINGCLOUD_API_KEY to your API key and replace the contents of Program.cs with this code:
using TXTextControl.ReportingCloud;
// Send the API key with every request
ReportingCloud reportingCloud = new ReportingCloud(
Environment.GetEnvironmentVariable("REPORTINGCLOUD_API_KEY"));
// One record with the fields and the item block of sample_invoice.tx
var invoice = new
{
invoice_no = "778723",
billto_name = "Joey Montana",
billto_companyname = "Montana, LLC",
item = new[]
{
new { qty = "1", item_no = "1", item_description = "Item description 1", item_total = "2130.40" },
new { qty = "1", item_no = "2", item_description = "Item description 2", item_total = "5543" }
},
total = "8210.538"
};
MergeBody mergeBody = new MergeBody
{
MergeData = new[] { invoice },
MergeSettings = new MergeSettings { DocumentTitle = "Invoice 778723" }
};
try
{
// Merge the stored template and return the documents as byte arrays
List<byte[]> documents = reportingCloud.MergeDocument(
mergeBody, "sample_invoice.tx", ReturnFormat.PDF);
File.WriteAllBytes("invoice.pdf", documents[0]);
Console.WriteLine("invoice.pdf has been written.");
}
catch (ArgumentException exception)
{
// The message is the response body of the failed request
Console.WriteLine(exception.Message);
}
The code works as follows:
MergeBodyis the request body.MergeDataholds the records, any object that serializes to a JSON array;Templatecan hold a template as a byte array instead of a template name;MergeSettingssets merge options and document properties.MergeDocumentsends the request to POST /v1/document/merge. Its parameters after the body aretemplateName(nullby default),returnFormat(ReturnFormat.PDF),append(true), which combines several records into one document, andtest(false).- The method returns a
List<byte[]>with one entry for each created document.ReturnFormathas the valuesPDF,PDFA,DOC,DOCX,RTF,TX,HTMLandTXT.
Merge Settings describes every option of MergeSettings.
How Merge Data Is Serialized
The class writes MergeData with Json.NET and a camel-case naming strategy: the capital letters at the start of each property name and dictionary key become lowercase. A property InvoiceNo is sent as invoiceNo and ID as id, while invoice_no stays as it is. Give your properties the names of the merge fields, as the anonymous type above does, so that the JSON keys match the template. Merge Data describes the structure of records, fields and blocks.
ReportingCloud Methods
| Method | Web API endpoint | Returns |
|---|---|---|
MergeDocument | POST /v1/document/merge | List<byte[]>, the merged documents |
AppendDocument | POST /v1/document/append | byte[], one document combined from an AppendBody |
ConvertDocument | POST /v1/document/convert | byte[], the document in the ReturnFormat |
FindAndReplaceDocument | POST /v1/document/findandreplace | byte[], the document with the text replaced |
GetDocumentThumbnails | POST /v1/document/thumbnails | One image per page, see Platform Differences |
ShareDocument | GET /v1/document/share | string, the encrypted name of a stored template for the viewer widget |
UploadTemplate | POST /v1/templates/upload | Nothing |
ListTemplates | GET /v1/templates/list | List<Template> with TemplateName, Modified and Size |
GetTemplateCount | GET /v1/templates/count | int |
TemplateExists | GET /v1/templates/exists | bool |
GetTemplateInfo | GET /v1/templates/info | TemplateInfo with the MergeFields and MergeBlocks of the template |
GetTemplatePageCount | GET /v1/templates/pagecount | int |
GetTemplateThumbnails | GET /v1/templates/thumbnails | One image per page, see Platform Differences |
DownloadTemplate | GET /v1/templates/download | byte[] |
DeleteTemplate | DELETE /v1/templates/delete | Nothing |
GetAccountSettings | GET /v1/account/settings | AccountSettings with the serial number, the quotas and their usage |
GetAccountAPIKeys | GET /v1/account/apikeys | List<APIKey> with Key and Active |
CreateAccountAPIKey | PUT /v1/account/apikey | string, the new key |
DeleteAccountAPIKey | DELETE /v1/account/apikey | bool |
ListFonts | GET /v1/fonts/list | string[] |
CheckText | GET /v1/proofing/check | List<IncorrectWord> |
GetAvailableDictionaries | GET /v1/proofing/availabledictionaries | string[] |
GetSuggestions | GET /v1/proofing/suggestions | string[] |
Processing.Review.GetTrackedChanges | POST /v1/processing/review/trackedchanges | List<TrackedChange> |
Processing.Review.RemoveTrackedChange | POST /v1/processing/review/removetrackedchange | TrackedChangeModifiedDocument with the Document and whether the change was Removed |
MergeDocument, AppendDocument, ConvertDocument and FindAndReplaceDocument take a test argument, the test parameter of the Web API: a test run adds a "TEST MODE" watermark, and a Free account can't use it. On a trial account, test runs of convert and append aren't counted against the document quota, and test runs of merge and find and replace are.
The methods add template names, the text of CheckText and the word of GetSuggestions to the query string without encoding them. A value with & or # arrives cut off, so encode such a value with Uri.EscapeDataString before you pass it.
Request Objects
| Class | Used by | Properties |
|---|---|---|
MergeBody | MergeDocument | MergeData, Template, MergeSettings |
MergeSettings | MergeDocument, FindAndReplaceDocument | RemoveEmptyFields, RemoveEmptyBlocks, RemoveEmptyImages, RemoveEmptyLines, RemoveTrailingWhitespace, MergeHtml, Culture and the properties of DocumentSettings; a property left null keeps the default of the Web API |
DocumentSettings | AppendDocument | Author, CreationDate, CreatorApplication, DocumentSubject, DocumentTitle, LastModificationDate, UserPassword |
AppendBody | AppendDocument | Documents, a list of AppendDocument objects, each with the Document as a byte array and a DocumentDivider (None, NewParagraph or NewSection); DocumentSettings |
FindAndReplaceBody | FindAndReplaceDocument | FindAndReplaceData, a List<string[]> of text to find and its replacement, Template and MergeSettings |
GetDocumentThumbnails and GetTemplateThumbnails take an ImageFormat: JPG, PNG, BMP or GIF.
Platform Differences
The builds for the three target frameworks differ in these members:
| Member | .NET Framework 4.5 | .NET Standard 1.3 and .NET Core 1.1 |
|---|---|---|
GetDocumentThumbnails, GetTemplateThumbnails | Return List<System.Drawing.Image> | Return List<string>, Base64-encoded images |
MergeSettings.Culture | System.Globalization.CultureInfo | string, such as "de-DE" |
TrackedChange.HighlightColor, TrackedChange.DefaultHighlightColor | System.Drawing.Color | string |
Errors
The methods are synchronous: each one waits for the response before it returns. When the Web API answers with an error, the method throws an ArgumentException whose Message is the response body; the HTTP status code isn't passed on. A request that gets no answer, such as one to an unreachable server, throws an AggregateException that holds the HttpRequestException. Errors and Status Codes lists the status codes and their causes, and its section Handle Errors in the SDKs tells the causes apart in code.
API Documentation and Source
- API documentation. The ReportingCloud .NET Wrapper API Documentation describes every class, property and method of the namespace
TXTextControl.ReportingCloud. - Source code. The repository TextControl/TXTextControl.ReportingCloud.DotNet holds the source under a BSD license and unit test projects for .NET Framework and .NET Core, which need the credentials of an account. Its last change to the code is from September 2, 2019, the day version 1.205.500 was published.