| layout | default-layout |
|---|---|
| needAutoGenerateSidebar | true |
| needGenerateH3Content | true |
| noTitleIndex | true |
| title | Angular Document Viewer - Dynamsoft Document Viewer Documentation |
| keywords | Documentation, Dynamsoft Document Viewer, PDF, Getting Started, Angular |
| breadcrumbText | Angular |
| description | Learn how to integrate Dynamsoft Document Viewer into your Angular project with this step-by-step guide. |
This guide will show you how to integrate Dynamsoft Document Viewer into an Angular project.
You can can download the sample on GitHub:
Make sure you have node and Angular CLI (v17 in this guide) installed.
Create a new Angular project.
ng new ddv-angular-
Install Dynamsoft Document Viewer.
npm install dynamsoft-document-viewer
-
Modify
angular.jsonto copy the resources of Dynamsoft Document Viewer and import its CSS.{ "assets": [ "src/favicon.ico", "src/assets", { "glob": "**/*", "input": "node_modules/dynamsoft-document-viewer/dist", "output": "/dynamsoft-document-viewer/dist" } ], "styles": [ "src/styles.css", "node_modules/dynamsoft-document-viewer/dist/ddv.css" ] }
-
Generate a viewer component.
ng generate component viewer
-
Add the following HTML code to
viewer.component.html.<div id="container"></div>
-
Add the following CSS code to
viewer.component.css.:host, #container { width: 100%; height: 100%; }
-
Add the following JavaScript code to
viewer.component.ts. It will bind Edit Viewer to a container. A license is set here. You can apply for a 30-day trial on this page.import { Component } from '@angular/core'; import { DDV } from 'dynamsoft-document-viewer'; @Component({ selector: 'app-viewer', standalone: true, imports: [], templateUrl: './viewer.component.html', styleUrl: './viewer.component.css' }) export class ViewerComponent { async ngOnInit() { DDV.on('error', (e) => { alert(e.message) }) // Public trial license which is valid for 24 hours DDV.Core.license = 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9'; DDV.Core.engineResourcePath = '/dynamsoft-document-viewer/dist/engine'; DDV.Core.loadWasm(); await DDV.Core.init(); const viewer = new DDV.EditViewer({ container: 'container' }); } }
-
Open
app.component.htmland add the viewer component.<style></style> <h1>Hello World for Angular</h1> <app-viewer ></app-viewer> <router-outlet></router-outlet>
-
Import the viewer component in
app.component.ts.import { ViewerComponent } from './components/viewer/viewer.component'; @Component({ selector: 'app-root', standalone: true, templateUrl: './app.component.html', styleUrl: './app.component.css', imports: [ CommonModule, RouterOutlet, ViewerComponent, ], })
-
Add CSS in
app.component.css.:host { width: 100%; height: 100%; display: flex; flex-direction: column; }
Run the app with the following command and you should see the viewer mounted in your application!
ng serveYou can find other samples on this GitHub repo.
