Angular: Typical Workflow with an ASP.NET Backend
TX Text Control for Angular provides visual components to edit and view documents in Angular based applications. This article explains typical workflows of how documents are merged with an ASP.NET Core backend Web API.

TX Text Control for Angular provides visual components to edit and view documents in Angular based applications. The document editor can be used to edit and create MS Word compatible documents in a true WYSIWYG manner.
A very common use-case scenario is using the Angular editor in combination with an ASP.NET (Core) backend to merge data into created templates.
A full tutorial on how to create a new ASP.NET Core back-end Web Application with an Angular front-end SPA can be found here:
Angular Applications with an ASP.NET Core Back-EndTypical Workflow
The following illustration shows the typical workflow:
In a common use-case, document templates with placeholder merge fields are created using the document editor in your Angular application.
Call the Web API
A TX Text Control powered Web API is called in TypeScript by passing the template to the backend (). After a successful merge, the returned document is loaded back into the document editor.
async mergeDocument() {
// get the saved document from TXTextControl
let postDocument: MergedDocument = {
document: await saveDocument(),
};
// post the document to endpoint 'MergeDocument'
this._http.post<MergedDocument>(this._baseUrl +
'textcontrol/mergedocument', postDocument).subscribe(result => {
// load the results into TXTextControl
loadDocument(result.document);
}, error => console.error(error));
}
The JavaScript function saveDocument saves the content of the document editor and loadDocument loads back a returned document:
function loadDocument(document) {
TXTextControl.loadDocument(TXTextControl.streamType.InternalUnicodeFormat, document);
}
function saveDocument() {
return new Promise(resolve => {
TXTextControl.saveDocument(TXTextControl.streamType.InternalUnicodeFormat, function (e) {
resolve(e.data);
});
});
}
Backend Controller
In the backend controller, the template is merged with data server-side and returned to the client ().
[ApiController]
[Route("[controller]")]
public class TextControlController : ControllerBase
{
[HttpPost]
[Route("MergeDocument")]
public MergedDocument MergeDocument([FromBody] MergedDocument Document)
{
byte[] data;
// create dummy merge data
Customer customer = new Customer() { Firstname = "Klaus", Name = "Klaasen" };
// new ServerTextControl instance
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
// load the document from the payload
tx.Load(Convert.FromBase64String(Document.Document),
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
TXTextControl.DocumentServer.MailMerge mm =
new TXTextControl.DocumentServer.MailMerge();
mm.TextComponent = tx;
mm.MergeObject(customer); // merge the data into template
// save document into byte array
tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// return the document to the client
return new MergedDocument() { Document = Convert.ToBase64String(data) };
}
}
}
Loading into DocumentViewer
Instead of loading the resulting document into the document editor, it can be presented in the read-only document viewer. In the following implementation of the mergeDocument method, the returned document is loaded into the document viewer instead the editor:
async mergeDocument() {
// get the saved document from TXTextControl
let postDocument: MergedDocument = {
document: await saveDocument(),
};
// post the document to endpoint 'MergeDocument'
this._http.post<MergedDocument>(this._baseUrl +
'textcontrol/mergedocument', postDocument).subscribe(result => {
// load the results into TXDocumentViewer
loadDocumentViewer(result.document);
}, error => console.error(error));
}
function loadDocument(Document) {
TXDocumentViewer.loadDocument(Document.documentData, Document.documentName);
}
To learn more details on how to load documents into the document viewer from an ASP.NET Core backend Web API, please have a look at the following article:
Loading Documents from an ASP.NET Core Backend Web APIAngular
Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.
Related Posts
Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor…
This article shows how to create a backend for the Document Editor and Viewer using ASP.NET Core. The backend can be hosted on Windows and Linux and can be used in Blazor, Angular, JavaScript, and…
Impressions from .NET Developer Conference DDC 2024
This week we sponsored the .NET Developer Conference DDC 2024 in Cologne, Germany. It was a great event with many interesting talks and workshops. Here are some impressions of the conference.
Back from Florida: Impressions from VSLive! Orlando 2024
We had an incredible time showcasing our digital document processing SDKs at VSLive! Orlando 2024 as a silver sponsor! Throughout the event, we interacted with hundreds of developers, shared…
Implementing a Security Middleware for Angular Document Editor Applications…
This article shows how to implement a security middleware for Angular Document Editor applications using ASP.NET Core. The middleware is used to validate access tokens and to protect the Document…
Meet Text Control at DDC .NET Developer Conference 2024
We are sponsoring the DDC .NET Developer Conference 2024 in Cologne, Germany. This 4-day conference is a great opportunity to meet the Text Control team and learn about the latest technologies in…