Angular: Loading and Saving Local Documents
This article shows how to load and save local documents using the Angular version of the document editor.

When using the Angular version of the TX Text Control document editor, documents are loaded client side using the JavaScript API. If you want to load documents from a server or repository, the document needs to be loaded from client-side (for example from a service endpoint) in order to be loaded into the editor.
Open Local Documents
To show how this works, this sample loads local documents that can be opened using a file open dialog.
-
Create a basic Angular application as described in this tutorial:
Creating your First Angular Application -
Create a folder named js in the folder src/assets/ and create a new JavaScript file named custom.js.
function saveDocument() { TXTextControl.saveDocument(TXTextControl.StreamType.AdobePDF, function (e) { bDocument = e.data; var element = document.createElement('a'); element.setAttribute('href', 'data:application/octet-stream;base64,' + e.data); element.setAttribute('download', "document.pdf"); element.style.display = 'none'; document.body.appendChild(element); // simulate click element.click(); // remove the link document.body.removeChild(element); }); } function readDocument(input) { input = input.srcElement; if (input.files && input.files[0]) { var fileReader = new FileReader(); fileReader.onload = function (e) { var streamType = TXTextControl.streamType.PlainText; // set the StreamType based on the lower case extension switch (fileinput.value.split('.').pop().toLowerCase()) { case 'doc': streamType = TXTextControl.streamType.MSWord; break; case 'docx': streamType = TXTextControl.streamType.WordprocessingML; break; case 'rtf': streamType = TXTextControl.streamType.RichTextFormat; break; case 'htm': streamType = TXTextControl.streamType.HTMLFormat; break; case 'tx': streamType = TXTextControl.streamType.InternalUnicodeFormat; break; case 'pdf': streamType = TXTextControl.streamType.AdobePDF; break; } // load the document beginning at the Base64 data (split at comma) TXTextControl.loadDocument(streamType, e.target.result.split(',')[1]); }; // read the file and convert it to Base64 fileReader.readAsDataURL(input.files[0]); } }
-
And add this JavaScript file to the scripts array of the projects architect/build/options element in the angular.json file:
"scripts": [ "src/assets/js/custom.js" ]
-
Add the declaration and the methods onChangeLoad and onClickSave to the app.component.ts TypeScript file, so that the complete file looks like this:
import { Component } from '@angular/core'; declare const readDocument: any; declare const saveDocument: any; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'my-editor-app'; onChangeLoad(event: any) { readDocument(event); } onClickSave() { saveDocument(); } }
-
Add a button and an input element to the app.component.html with the Angular click and change handlers:
<div class="fileButtons"> <input (change)="onChangeLoad($event)" type="file" id="fileinput" /> <input (click)="onClickSave()" type="button" value="Save as PDF" /> </div> <tx-document-editor width="1024" height="800" port="8080"></tx-document-editor>
When starting this Angular application, a file open dialog is opened to choose a local document that is then loaded into the document editor. When clicking the Save as PDF button, the document is saved and downloaded as an Adobe PDF document.
Try this on your own and create your first Angular application without installing any setup. Simply by downloading the npm packages.
Creating your First Angular Application
Loading Documents on Initialization
If you want to load a document on initializing TX Text Control, please have a look at this article:
Angular
Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.
Related Posts
Creating an Angular Document Editor Application with a Node.js WebSocket Server
This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.
Reuse Persistent Document Editor Components in Angular SPA Applications
An Angular Single Page Application (SPA) dynamically updates the web page without reloading by loading all necessary resources once. This article demonstrates how to reuse persistent Document…
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…
AngularJavaScriptDocument Editor
Getting Started: Document Editor Version 33.0 with Angular CLI 19.0
This article shows how to use the TX Text Control Document Editor version 33.0 npm package for Angular within an Angular CLI 19.0 application. It uses the trial backend running on our servers, but…
AngularASP.NET CoreDocument Editor
Changing the Language in the Angular Document Editor Using the Resource Kit
This article walks you through the process of building a satellite assembly using the Resource Kit to customize the language of the TX Text Control interface in the Angular Document Editor.