@txtextcontrol/tx-ng-ds-document-processing
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

TX Text Control DS Server Document Processing (Angular version)

Angular service for DS Server Web API. Authored and supported by Text Control GmbH.

Installation

ng add @txtextcontrol/tx-ng-ds-document-processing

Important notice: From Angular v17 onwards, "standalone" apps are the new default for the CLI. If you want DocumentProcessingModule to be added to your app.module.ts automatically, you have to use the --no-standalone flag when creating a new Angular project with ng new. Standalone applications created without this flag will show the error Bootstrap call not found when using the ng add command.

Usage

  1. Import the service and supporting modules / classes in your main module

    import { HttpClientModule } from '@angular/common/http';
    import { 
       DocumentProcessingService,
       OAuthSettings
    } from '@txtextcontrol/tx-ng-ds-document-processing';
  2. If necessary, declare an OAuth settings object in your main module for later injection

    const DS_OAUTH_SETTINGS: OAuthSettings = {
       clientID: 'dsserver.sdnkRXtvlOfb8PhIzhsRNO1JQ5KidEI0',
       clientSecret: 'Oi52LTzmIGsNx88GEdoWSsy8R8Tu1bmx'
    };
  3. Declare the service and additional settings as providers in your main module

    [...]
    
    @NgModule({
       declarations: [...],
       imports: [
          ...,
          HttpClientModule
       ],
       providers: [
          DocumentProcessingService,
          { provide: 'dsOAuthSettings', useValue: DS_OAUTH_SETTINGS },
          { provide: 'dsServiceUrl', useValue: 'https://your-server.com/documentservices' }
          // { provide: 'dsAccessToken', useValue: 'GEdoWSsy8R8Tu1bmxOi52LTzmIGsNx88' }
          // If an access token is provided via dsAccessToken, any value provided
          // via dsOAuthSettings is ignored.
       ],      
       bootstrap: [...]
    })
    export class AppModule { }
  4. Inject the service into your component

    import { Component } from '@angular/core';
    import { DocumentProcessingService } from '@txtextcontrol/tx-ng-ds-document-processing';
    
    @Component({
       selector: 'foo',
       template: `foobar`
    })
    export class FooComponent {
    
       constructor(private dpService: DocumentProcessingService) { }
    
       ngAfterViewInit(): void {
          // Convert a simple RTF document to PDF and display the resulting 
          // document in an iframe
          const rtfDoc = '{\\rtf{\\fonttbl {\\f0 Arial;}}\\f0\\fs60 Hello, DSServer!}';
          this.dpService.document.convert(btoa(rtfDoc)).then(result => {
             const dataURL = `data:application/pdf;base64,${result}`;
             const div = document.createElement('div');
             div.innerHTML = `<h3>Conversion result</h3><iframe style="width:800px;height:800px" src="${dataURL}"></iframe>`;
             document.body.appendChild(div);
          });
       }
    }

Environment Support

Readme

Keywords

none

Package Sidebar

Install

npm i @txtextcontrol/tx-ng-ds-document-processing

Weekly Downloads

6

Version

4.0.0

License

ISC

Unpacked Size

269 kB

Total Files

82

Last publish

Collaborators

  • thomerow
  • bjoerntx
  • schedo