Build an Angular PDF viewer with Apryse WebViewer SDK
This guide shows how to build an Angular PDF viewer using the Apryse WebViewer SDK. You'll learn how to integrate the SDK into an Angular application to render, view, and interact with PDF documents using the WebViewer UI.
You can also download a ready-to-use GitHub sample to get started quickly, or explore the interactive Showcase demo to see WebViewer's full capabilities in action.
Prerequisites
This guide assumes basic familiarity with Angular development. Before you start:
Install Node.js and npm. See the Angular documentation for version details.
Install Visual Studio Code or another code editor to develop and debug your code.
Get your Apryse trial key.
1. Create an Angular project
In this section, you’ll create a new Angular application using npm. This project provides the foundation for integrating Apryse WebViewer. If you already have an Angular app, skip this and continue to Install WebViewer.
In your terminal, install the Angular CLI globally so you can create and manage Angular projects:
npm install -g @angular/cliNavigate to the directory where you want to create the project.
Create a new
webviewer-angularproject using a minimal setup:
ng new webviewer-angular --style=css --ssr=false --defaultsNavigate to your new Angular project directory and install dependencies:
2. Install WebViewer
Next, install the Apryse WebViewer SDK using npm. This command adds the WebViewer package to your project, allowing you to integrate the PDF viewer and editor into your Angular application.
After navigating to your webviewer-angular project directory, run the following command to install WebViewer:
3. Copy WebViewer assets
WebViewer requires access to its static assets at runtime, including WebAssembly modules, HTML, and CSS files. These assets are located in node_modules/@pdftron/webviewer/public. To ensure they’re served correctly, make them publicly accessible in your Angular application by configuring the assets array in angular.json. In this section, you’ll copy the required WebViewer assets to a location that Angular serves automatically. For more, see Copying WebViewer static assets.
Open your project in Visual Studio Code and go to the
angular.jsonfile.In the
angular.jsonfile, update theassetsarray to include the following and save:
The output value creates a new set of folders and moves the static assets to the lib/webviewer folder.
4. Create the PDF viewer
In this section, you'll add WebViewer to your Angular app by creating a component and initializing the viewer. This mounts the WebViewer UI and loads a document in your application.
Create a
webviewerfolder in your project'ssrcdirectory:
Create
webviewer.tsandwebviewer.htmlfiles in thewebviewerfolder:
In Visual Studio Code, add this code to the
webviewer.tsfile and save:
Add this code to the
webviewer.htmlfile and save:
Replace the
src/app/app.tsfile with the following and save:
Replace the
src/app/app.htmlfile with the following and save:
5. Verify your output
You can now load and display a PDF document in the WebViewer UI. Run your Angular application to launch WebViewer and see the PDF in your browser.
From your project directory, run the following command to start the application:
A successful output looks similar to:
Open the localhost URL from your terminal to view the WebViewer UI and PDF document.
Get started video
In this 5-minute video, learn how to install and integrate the Apryse WebViewer SDK into an Angular project.
Next steps
Last updated
Was this helpful?