X15: Inserting Client-Side Images using JavaScript
Using JavaScript API enhancements, client-side images can be added to documents. This article shows how to add a client-side image using a file input form element.

Using JavaScript API enhancements, client-side images can be added to documents. All supported image types can be added as Base64 encoded strings and inserted at character position, anchored to paragraphs or fixed on pages.
The TXText
| Method | Description |
|---|---|
| addAnchored | Inserts a new image which is anchored to the specified text position. |
| addAnchoredAtLocation | Inserts a new image which is anchored to the specified text position. |
| addAtFixedPosition | Inserts a new image which has a fixed geometrical position in the document. |
| addInline | Inserts an image inline, which means that it is treated in the text like a single character. |
Consider the following ASP.NET MVC view that consists of a simple HTML file input element and a TextControl:
@using TXTextControl.Web.MVC
@using TXTextControl.Web
<input type="file" id="file" name="file" enctype="multipart/form-data" />
@Html.TXTextControl().TextControl(settings =>
{
}).Render()
The following JavaScript code reads the content of an opened local image, converts it to a Base64 encoded string and finally adds the image to the document:
document.getElementById('file').addEventListener('change', readFile, false);
function readFile(evt) {
var files = evt.target.files;
var file = files[0];
var reader = new FileReader();
reader.onload = function (event) {
var binaryString = btoa(event.target.result);
TXTextControl.images.addInline(binaryString, -1);
}
reader.readAsBinaryString(file);
}
In the following sample, that can be downloaded directly from our GitHub account, an additional ribbon menu item is added that opens a dialog box to add local images.

Also See
This post references the following in the documentation:
- Javascript: Image
Collection.add Anchored Method - Javascript: Image
Collection.add Anchored At Location Method - Javascript: Image
Collection.add At Fixed Position Method - Javascript: Image
Collection.add Inline Method - TXText
Control. Image Collection Class
![]()
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2015 or better
- TX Text Control .NET Server X15 (trial sufficient)
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
X15: Adding MS Word Compatible Fields and Form Elements to TXTextControl.Web
This article explains how to insert MS Word compatible form fields and form elements to documents.
PDF/UA vs. PDF/A-3a: Which Format Should You Use for Your Business Application?
In this blog post, we will explore the differences between PDF/UA and PDF/A-3a, helping you choose the right format for your business needs. We will discuss the key features, benefits, and use…
Validating PDF/UA Documents in .NET C#
Creating accessible and compliant PDF documents is becoming an increasingly important requirement across industries. In this blog post, we explore how to validate PDF/UA documents using Text…
Sneak Peek: TX Text Control 34.0 Coming November 2025
We are excited to announce the upcoming release of TX Text Control 34.0, scheduled for November 2025. This update brings a host of new features and improvements to enhance your document processing…
TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
