Angular Image & PDF Viewer

January 13, 2026 ยท View on GitHub

npm version License: MIT Downloads StackBlitz

A premium, highly customizable Angular library for viewing PDF documents and images. Built with performance in mind using Mozilla's pdf.js engine, it offers a seamless "Google Drive-like" preview experience for your Angular applications.


โœจ Features at a Glance

FeatureDescription
๐Ÿ“„ Dual ModeSmartly switches between PDF and Image viewing (PNG, JPG, WEBP, SVG).
๐Ÿ” Smart ZoomMouse-wheel zoom, pinch-to-zoom, and preset zoom levels (50% - 300%).
๐Ÿ”„ RotationRotate documents 90ยฐ clockwise or counter-clockwise on the fly.
๐Ÿ› ๏ธ Smart ProxyIndustrial-grade strategy: direct access first, then "smart" proxy fallback.
๐Ÿงฉ HeuristicsDetects doc types without extensions by analyzing URL path patterns.
๐Ÿ“ฑ ResponsiveLogic that adapts to any screen size, mobile or desktop.
๐Ÿ–ฅ๏ธ FullscreenNative immersive mode for distraction-free reading.

๐Ÿ“ฆ Installation

Install the library and its peer dependencies:

npm install img-pdf-viewer

๐Ÿš€ Quick Start Guide

StackBlitz

Follow these 4 simple steps to integrate the viewer into your app.

1๏ธโƒฃ Import the Module

In your app.module.ts:

import { ImgPdfViewerModule } from "img-pdf-viewer";

@NgModule({
  imports: [
    ImgPdfViewerModule,
    // ...
  ],
})
export class AppModule {}

2๏ธโƒฃ Define Configuration

In your component (e.g., app.component.ts), set up the document URL and optional config:

import { DocumentViewerConfig } from "img-pdf-viewer";

export class AppComponent {
  // Your PDF or Image URL (can be from an API or local asset)
  docUrl = "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf";

  // Customize the look and feel
  config: DocumentViewerConfig = {
    showToolbar: true,
    showZoom: true,
    showRotation: true,
    showDownload: true,
    showFullscreen: true,
    initialZoom: 100,
    viewMode: "single", // Options: 'single' | 'continuous'
  };
}

3๏ธโƒฃ Add to Template

In your HTML (app.component.html), drop in the component:

<div class="viewer-host">
  <ngx-imgPdf-viewer [documentUrl]="docUrl" [config]="config" [title]="'Project Documentation'"> </ngx-imgPdf-viewer>
</div>

4๏ธโƒฃ Set Container Height

Warning

The viewer takes the height of its parent. If the parent has 0px height, the viewer will be invisible!

In app.component.css:

.viewer-host {
  height: 100vh; /* Make it full screen */
  width: 100%;
  border: 1px solid #ddd; /* Optional: adds a nice border */
}

๐Ÿ› ๏ธ Advanced Configuration

The DocumentViewerConfig interface allows you to granularly control the UI:

PropertyTypeDefaultDescription
showToolbarbooleantrueShow or hide the top toolbar.
showZoombooleantrueEnable zoom-in and zoom-out buttons.
showRotationbooleantrueEnable rotation controls.
showDownloadbooleantrueAllow users to download the source file.
showFullscreenbooleantrueEnable the fullscreen toggle button.
viewMode'single' | 'continuous''single'Single: Page-by-page. Continuous: Scroll through all pages.
initialZoomnumber100Start percentage for zoom.
proxyUrlstringundefinedCustom proxy to bypass CORS (e.g., https://corsproxy.io/?).
fallbackType'pdf' | 'image'undefinedType to use if auto-detection fails for extensionless URLs.
heightstring'100vh'Height of the viewer container.

๐Ÿค Contribution

We love open source! If you'd like to contribute:

  1. Fork the repo.
  2. Create a branch (git checkout -b feature/amazing-feature).
  3. Commit your changes.
  4. Open a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with โค๏ธ by Niranjan Kushwaha