ng2-pdf-viewer vs ngx-extended-pdf-viewer vs pdfjs-dist vs react-pdf vs vue-pdf-embed
PDF Rendering Libraries for Web Applications
ng2-pdf-viewerngx-extended-pdf-viewerpdfjs-distreact-pdfvue-pdf-embedSimilar Packages:

PDF Rendering Libraries for Web Applications

ng2-pdf-viewer, ngx-extended-pdf-viewer, pdfjs-dist, react-pdf, and vue-pdf-embed are all npm packages designed to render PDF documents in web applications, leveraging Mozilla's PDF.js under the hood. pdfjs-dist is the official, low-level JavaScript library that provides core PDF parsing and rendering capabilities. The other four packages are framework-specific wrappers: ng2-pdf-viewer and ngx-extended-pdf-viewer target Angular, react-pdf targets React, and vue-pdf-embed targets Vue. While they all solve the same fundamental problem — displaying PDFs in the browser — they differ significantly in terms of abstraction level, built-in features (like text selection, search, and navigation controls), rendering approach (canvas vs. SVG), and ease of integration within their respective ecosystems.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
ng2-pdf-viewer0-282 kB-a year agoMIT
ngx-extended-pdf-viewer057454.2 MB1420 days agoApache-2.0
pdfjs-dist053,31935.3 MB44919 days agoApache-2.0
react-pdf011,064309 kB193 months agoMIT
vue-pdf-embed01,0235.26 MB92 months agoMIT

PDF Rendering in Modern Web Apps: A Deep Dive into Popular Libraries

Displaying PDFs in the browser is a common requirement, but choosing the right library depends heavily on your framework, feature needs, and performance constraints. All five packages—ng2-pdf-viewer, ngx-extended-pdf-viewer, pdfjs-dist, react-pdf, and vue-pdf-embed—are built on Mozilla’s PDF.js, but they differ significantly in abstraction level, framework integration, and capabilities. Let’s break down how they work in practice.

🧱 Core Architecture: Wrapper vs Direct Use

pdfjs-dist is the official, low-level PDF.js distribution. It gives you full control but requires manual DOM management, worker setup, and rendering logic.

// pdfjs-dist: Manual rendering
import * as pdfjsLib from 'pdfjs-dist';
import { getDocument } from 'pdfjs-dist/webpack';

pdfjsLib.GlobalWorkerOptions.workerSrc = './pdf.worker.min.js';

const loadingTask = getDocument('sample.pdf');
const pdf = await loadingTask.promise;
const page = await pdf.getPage(1);

const canvas = document.getElementById('pdf-canvas');
const context = canvas.getContext('2d');
const viewport = page.getViewport({ scale: 1.5 });

canvas.height = viewport.height;
canvas.width = viewport.width;

await page.render({ canvasContext: context, viewport }).promise;

ng2-pdf-viewer, ngx-extended-pdf-viewer, react-pdf, and vue-pdf-embed are framework-specific wrappers that abstract away this boilerplate.

// ng2-pdf-viewer (Angular)
<pdf-viewer [src]="'sample.pdf'" [page]="1"></pdf-viewer>
// react-pdf (React)
import { Document, Page } from 'react-pdf';

<Document file="sample.pdf">
  <Page pageNumber={1} />
</Document>
<!-- vue-pdf-embed (Vue) -->
<template>
  <vue-pdf-embed :src="'sample.pdf'" page="1" />
</template>

🔍 Text Selection & Search: Built-in vs DIY

ngx-extended-pdf-viewer includes full text layer support out of the box, enabling copy-paste, search, and accessibility features without extra code.

<!-- ngx-extended-pdf-viewer -->
<ngx-extended-pdf-viewer
  [src]="'sample.pdf'"
  [showHandTool]="true"
  [showFindButton]="true"
></ngx-extended-pdf-viewer>

react-pdf supports text layers via the renderTextLayer prop, but you must enable it explicitly:

<Page pageNumber={1} renderTextLayer={true} />

ng2-pdf-viewer and vue-pdf-embed do not include text layer rendering by default. You’d need to extend them or use pdfjs-dist directly for this functionality.

pdfjs-dist gives you complete control—you can render text layers manually using page.getTextContent() and pdfjsLib.renderTextLayer().

📏 Zoom, Rotation, and Navigation Controls

ngx-extended-pdf-viewer ships with a full toolbar (zoom, rotate, print, download, search, etc.) that’s highly configurable.

<ngx-extended-pdf-viewer
  [src]="pdfSrc"
  [zoom]="1.5"
  [rotation]="90"
  [showZoomButtons]="true"
></ngx-extended-pdf-viewer>

react-pdf provides no UI controls—you build your own toolbar and manage state (e.g., current page, zoom level) manually:

const [pageNumber, setPageNumber] = useState(1);

return (
  <div>
    <button onClick={() => setPageNumber(prev => prev - 1)}>Prev</button>
    <Document file="sample.pdf">
      <Page pageNumber={pageNumber} />
    </Document>
    <button onClick={() => setPageNumber(prev => prev + 1)}>Next</button>
  </div>
);

ng2-pdf-viewer offers basic navigation events (pageChange, error) but no built-in UI. vue-pdf-embed is similarly minimal—just a single-page embed component.

⚙️ Worker and Bundle Management

All libraries rely on PDF.js’s worker for performance. How they handle it varies:

  • pdfjs-dist: You must configure the worker path manually (as shown earlier).
  • react-pdf: Uses a custom webpack loader or requires explicit worker import:
    import { pdfjs } from 'react-pdf';
    pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;
    
  • ngx-extended-pdf-viewer: Bundles optimized worker files and handles loading automatically.
  • ng2-pdf-viewer and vue-pdf-embed: Require manual worker setup similar to pdfjs-dist.

🖼️ Rendering Performance and Quality

ngx-extended-pdf-viewer uses SVG rendering by default (with optional canvas), which provides sharp text at any zoom level and better accessibility.

react-pdf, ng2-pdf-viewer, and vue-pdf-embed use canvas rendering, which is faster for complex pages but results in blurry text when zoomed.

pdfjs-dist lets you choose: page.render() for canvas, or page.getTextContent() + renderTextLayer() for SVG-like text.

🧩 Framework Integration Depth

  • Angular: ngx-extended-pdf-viewer is far more feature-complete than ng2-pdf-viewer. The latter is essentially a basic wrapper with limited customization.
  • React: react-pdf is the de facto standard, though it requires more manual work for advanced features.
  • Vue: vue-pdf-embed is lightweight but only handles single-page rendering. For multi-page or interactive features, you’d likely need to drop down to pdfjs-dist.

🛑 Deprecation and Maintenance Status

As of 2024:

  • ng2-pdf-viewer is still maintained but largely superseded by ngx-extended-pdf-viewer for non-trivial use cases.
  • ngx-extended-pdf-viewer, pdfjs-dist, react-pdf, and vue-pdf-embed are actively maintained with recent releases.

📊 Summary Table

Featureng2-pdf-viewerngx-extended-pdf-viewerpdfjs-distreact-pdfvue-pdf-embed
FrameworkAngularAngularNoneReactVue
Text Layer✅ (manual)✅ (opt-in)
Built-in Toolbar
Multi-page View✅ (manual)❌ (single page)
Rendering ModeCanvasSVG (default) / CanvasBothCanvasCanvas
Worker HandlingManualAutomaticManualManualManual

💡 When to Use What

  • Need a quick Angular PDF viewer with full features? → ngx-extended-pdf-viewer
  • Building a custom React PDF experience and don’t mind wiring up controls? → react-pdf
  • Working in Vue and only need to show one page? → vue-pdf-embed
  • Require maximum control or are building a framework-agnostic solution? → pdfjs-dist
  • Using Angular but only need basic rendering and want minimal bundle impact? → ng2-pdf-viewer (but consider if ngx-extended-pdf-viewer’s features justify its size)

The key takeaway: Don’t default to the simplest wrapper. If you need text selection, search, or responsive zoom, the extra setup of ngx-extended-pdf-viewer or manual pdfjs-dist usage will save you headaches later.

How to Choose: ng2-pdf-viewer vs ngx-extended-pdf-viewer vs pdfjs-dist vs react-pdf vs vue-pdf-embed

  • ng2-pdf-viewer:

    Choose ng2-pdf-viewer if you're working in an Angular application and need a lightweight, basic PDF viewer that displays single or multiple pages with minimal setup. It's suitable for simple use cases where you don't require text selection, search functionality, or a built-in toolbar, and you're comfortable handling PDF.js worker configuration manually. However, for any advanced requirements, consider ngx-extended-pdf-viewer instead, as this package offers limited extensibility.

  • ngx-extended-pdf-viewer:

    Choose ngx-extended-pdf-viewer if you're building an Angular application that demands a full-featured, production-ready PDF viewer with built-in support for text selection, search, zoom, rotation, printing, and a customizable toolbar. It handles worker loading automatically, uses SVG rendering by default for crisp text, and is actively maintained. This is the go-to choice for Angular projects requiring robust PDF interaction without reinventing the wheel.

  • pdfjs-dist:

    Choose pdfjs-dist if you need maximum control over PDF rendering, are building a framework-agnostic solution, or require custom behavior not supported by higher-level wrappers. You'll manage DOM elements, worker setup, text layers, and event handling yourself, but gain the flexibility to implement exactly what your application needs. This is ideal for teams with deep PDF.js expertise or those building specialized document viewers.

  • react-pdf:

    Choose react-pdf if you're developing a React application and prefer a component-based API that integrates naturally with React's state and lifecycle. It supports text layers (when enabled) and multi-page rendering, but requires you to build your own UI controls for navigation, zoom, and search. It's the standard choice for React projects, balancing ease of use with sufficient customization for most common scenarios.

  • vue-pdf-embed:

    Choose vue-pdf-embed if you're using Vue and only need to embed a single PDF page without interactive features like text selection, search, or navigation controls. It's a minimal wrapper around PDF.js with straightforward props, but lacks multi-page support and built-in UI. For anything beyond basic static display, you'll likely need to combine it with pdfjs-dist or consider alternative approaches.

README for ng2-pdf-viewer

Angular PDF Viewer

downloads npm version Gitter PayPal donate button

PDF Viewer Component for Angular 5+

Demo page

https://vadimdez.github.io/ng2-pdf-viewer/

Stackblitz Example

https://stackblitz.com/edit/ng2-pdf-viewer

Blog post

https://medium.com/@vadimdez/render-pdf-in-angular-4-927e31da9c76

Overview

Install

Angular >= 12

npm install ng2-pdf-viewer

Partial Ivy compilated library bundles.

Angular >= 4

npm install ng2-pdf-viewer@^7.0.0

Angular < 4

npm install ng2-pdf-viewer@~3.0.8

Usage

In case you're using systemjs see configuration here.

Add PdfViewerModule to your module's imports

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';

import { PdfViewerModule } from 'ng2-pdf-viewer';

@NgModule({
  imports: [BrowserModule, PdfViewerModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})

class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);

And then use it in your component

import { Component } from '@angular/core';

@Component({
  selector: 'example-app',
  template: `
  <pdf-viewer [src]="pdfSrc"
              [render-text]="true"
              [original-size]="false"
              style="width: 400px; height: 500px"
  ></pdf-viewer>
  `
})
export class AppComponent {
  pdfSrc = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
}

Options

[src]

PropertyTypeRequired
[src]string, object, UInt8ArrayRequired

Pass pdf location

[src]="'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf'"

For more control you can pass options object to [src]. See other attributes for the object here.

Options object for loading protected PDF would be:

{
 url: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
 withCredentials: true
}

[page]

PropertyTypeRequired
[page] or [(page)]numberRequired with [show-all]="false" or Optional with [show-all]="true"

Page number

[page]="1"

supports two way data binding as well

[(page)]="pageVariable"

If you want that the two way data binding actually updates your page variable on page change/scroll - you have to be sure that you define the height of the container, for example:

pdf-viewer {
    height: 100vh;
}

[stick-to-page]

PropertyTypeRequired
[stick-to-page]booleanOptional

Sticks view to the page. Works in combination with [show-all]="true" and page.

[stick-to-page]="true"

[render-text]

PropertyTypeRequired
[render-text]booleanOptional

Enable text rendering, allows to select text

[render-text]="true"

[render-text-mode]

PropertyTypeRequired
[render-text-mode]RenderTextModeOptional

Used in combination with [render-text]="true"

Controls if the text layer is enabled, and the selection mode that is used.

0 = RenderTextMode.DISABLED - disable the text selection layer

1 = RenderTextMode.ENABLED - enables the text selection layer

2 = RenderTextMode.ENHANCED - enables enhanced text selection

[render-text-mode]="1"

[external-link-target]

PropertyTypeRequired
[external-link-target]stringOptional

Used in combination with [render-text]="true"

Link target

  • blank
  • none
  • self
  • parent
  • top
[external-link-target]="'blank'"

[rotation]

PropertyTypeRequired
[rotation]numberOptional

Rotate PDF

Allowed step is 90 degree, ex. 0, 90, 180

[rotation]="90"

[zoom]

PropertyTypeRequired
[zoom]numberOptional

Zoom pdf

[zoom]="0.5"

[zoom-scale]

PropertyTypeRequired
[zoom-scale]'page-width'|'page-fit'|'page-height'Optional

Defines how the Zoom scale is computed when [original-size]="false", by default set to 'page-width'.

  • 'page-width' with zoom of 1 will display a page width that take all the possible horizontal space in the container

  • 'page-height' with zoom of 1 will display a page height that take all the possible vertical space in the container

  • 'page-fit' with zoom of 1 will display a page that will be scaled to either width or height to fit completely in the container

[zoom-scale]="'page-width'"

[original-size]

PropertyTypeRequired
[original-size]booleanOptional
  • if set to true - size will be as same as original document
  • if set to false - size will be as same as container block
[original-size]="true"

[fit-to-page]

PropertyTypeRequired
[fit-to-page]booleanOptional

Works in combination with [original-size]="true". You can show your document in original size, and make sure that it's not bigger then container block.

[fit-to-page]="false"

[show-all]

PropertyTypeRequired
[show-all]booleanOptional

Show single or all pages altogether

[show-all]="true"

[autoresize]

PropertyTypeRequired
[autoresize]booleanOptional

Turn on or off auto resize.

!Important To make [autoresize] work - make sure that [original-size]="false" and pdf-viewer tag has max-width or display are set.

[autoresize]="true"

[c-maps-url]

PropertyTypeRequired
[c-maps-url]stringOptional

Url for non-latin characters source maps.

[c-maps-url]="'assets/cmaps/'"

Default url is: https://unpkg.com/pdfjs-dist@2.0.550/cmaps/

To serve cmaps on your own you need to copy node_modules/pdfjs-dist/cmaps to assets/cmaps.

[show-borders]

PropertyTypeRequired
[show-borders]booleanOptional

Show page borders

[show-borders]="true"

(after-load-complete)

PropertyTypeRequired
(after-load-complete)callbackOptional

Get PDF information with callback

First define callback function "callBackFn" in your controller,

callBackFn(pdf: PDFDocumentProxy) {
   // do anything with "pdf"
}

And then use it in your template:

(after-load-complete)="callBackFn($event)"

(page-rendered)

PropertyTypeRequired
(page-rendered)callbackOptional

Get event when a page is rendered. Called for every page rendered.

Define callback in your component:

pageRendered(e: CustomEvent) {
  console.log('(page-rendered)', e);
}

And then bind it to <pdf-viewer>:

(page-rendered)="pageRendered($event)"

(pages-initialized)

PropertyTypeRequired
(pages-initialized)callbackOptional

Get event when the pages are initialized.

Define callback in your component:

pageInitialized(e: CustomEvent) {
  console.log('(pages-initialized)', e);
}

And then bind it to <pdf-viewer>:

(pages-initialized)="pageInitialized($event)"

(text-layer-rendered)

PropertyTypeRequired
(text-layer-rendered)callbackOptional

Get event when a text layer is rendered.

Define callback in your component:

textLayerRendered(e: CustomEvent) {
  console.log('(text-layer-rendered)', e);
}

And then bind it to <pdf-viewer>:

(text-layer-rendered)="textLayerRendered($event)"

(error)

PropertyTypeRequired
(error)callbackOptional

Error handling callback

Define callback in your component's class

onError(error: any) {
  // do anything
}

Then add it to pdf-component in component's template

(error)="onError($event)"

(on-progress)

PropertyTypeRequired
(on-progress)callbackOptional

Loading progress callback - provides progress information total and loaded bytes. Is called several times during pdf loading phase.

Define callback in your component's class

onProgress(progressData: PDFProgressData) {
  // do anything with progress data. For example progress indicator
}

Then add it to pdf-component in component's template

(on-progress)="onProgress($event)"

Render local PDF file

In your html template add input:

<input (change)="onFileSelected()" type="file" id="file">

and then add onFileSelected method to your component:

onFileSelected() {
  let $img: any = document.querySelector('#file');

  if (typeof (FileReader) !== 'undefined') {
    let reader = new FileReader();

    reader.onload = (e: any) => {
      this.pdfSrc = e.target.result;
    };

    reader.readAsArrayBuffer($img.files[0]);
  }
}

Set custom path to the worker

By default the worker is loaded from cdn.jsdelivr.net.

In your code update path to the worker to be for example /pdf.worker.mjs

(window as any).pdfWorkerSrc = '/pdf.worker.mjs';

This should be set before pdf-viewer component is rendered.

If you ever have a (super rare) edge case where you run in an environment that multiple components are somehow loaded within the same web page, sharing the same window, but using different versions of pdf.worker, support has been added. You can do the above, except that you can append the specific version of pdfjs required and override the custom path just for that version. This way setting the global window var won't conflict.

(window as any)["pdfWorkerSrc2.14.305"] = '/pdf.worker.mjs';

Search in the PDF

Use eventBus for the search functionality.

In your component's ts file:

  • Add reference to pdf-viewer component,
  • then when needed execute search() like this:
@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;

search(stringToSearch: string) {
  this.pdfComponent.eventBus.dispatch('find', {
    query: stringToSearch, type: 'again', caseSensitive: false, findPrevious: undefined, highlightAll: true, phraseSearch: true
  });
}

Contribute

See CONTRIBUTING.md

Donation

If this project help you reduce time to develop, you can give me a cup of tea :)

paypal

License

MIT © Vadym Yatsyuk