UNPKG

ngx-universal-file-viewer

Version:

A powerful Angular component for viewing PDF, Word, Excel, and PowerPoint files with continuous scroll and page-by-page view modes. Supports Angular 12+

144 lines (115 loc) • 4.12 kB
# NgxUniversalFileViewer [![npm version](https://badge.fury.io/js/ngx-universal-file-viewer.svg)](https://www.npmjs.com/package/ngx-universal-file-viewer) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Angular](https://img.shields.io/badge/Angular-12%2B-red)](https://angular.io/) A powerful and versatile Angular component for viewing multiple file formats including PDF, Word (DOC/DOCX), Excel (XLS/XLSX), and PowerPoint (PPT/PPTX) files with both continuous scroll and page-by-page view modes. ## ✨ Features - šŸ“„ **PDF Viewer** - Full-featured PDF viewing with zoom, rotation, navigation - šŸ“ **Word Documents** - Display DOC and DOCX files with proper formatting - šŸ“Š **Excel Spreadsheets** - View XLS and XLSX files with sheet navigation - šŸ“½ļø **PowerPoint Presentations** - View PPT and PPTX slides - šŸ”„ **Dual View Modes** - Toggle between continuous scroll and page-by-page view - šŸŽØ **Customizable Toolbar** - Configure which controls to display - šŸ“± **Responsive Design** - Works seamlessly on desktop and mobile devices - šŸ” **Auto File Type Detection** - Automatically detects file type from extension - 🌐 **SSR Compatible** - Works with Angular Universal - šŸ’Ŗ **TypeScript Support** - Fully typed for better development experience ## šŸ“¦ Installation ### Step 1: Install the package ```bash npm install ngx-universal-file-viewer ``` #### Or Using Yarn: ```bash yarn add ngx-universal-file-viewer ``` šŸš€ Getting Started For Angular 14+ (Standalone Components) ```bash import { Component } from '@angular/core'; import { NgxUniversalFileViewerComponent } from 'ngx-universal-file-viewer'; @Component({ selector: 'app-document-viewer', standalone: true, imports: [NgxUniversalFileViewerComponent], template: ` <ngx-universal-file-viewer [src]="fileUrl" [fileType]="'auto'" [viewMode]="'continuous'"> </ngx-universal-file-viewer> ` }) export class DocumentViewerComponent { fileUrl = 'assets/sample.pdf'; } ``` For Angular 12-13 (Module-based) ```bash import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { NgxUniversalFileViewerComponent } from 'ngx-universal-file-viewer'; import { AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, NgxUniversalFileViewerModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } ``` šŸ“– Basic Usage Simple Implementation ```bash <ngx-universal-file-viewer [src]="fileUrl" [fileType]="'auto'" [viewMode]="'continuous'" [showToolbar]="true" > </ngx-universal-file-viewer> ``` TypeScript ```bash export class AppComponent { fileUrl = 'https://example.com/document.pdf'; } ``` With All Options ```bash <ngx-universal-file-viewer [src]="fileSource" [fileType]="fileType" [viewMode]="viewMode" [showToolbar]="showToolbar" [viewerConfig]="viewerConfig" [toolbarConfig]="toolbarConfig" (onLoad)="handleLoad($event)" (onError)="handleError($event)" (pageChange)="handlePageChange($event)" (viewModeChange)="handleViewModeChange($event)"> </ngx-universal-file-viewer> ``` ### šŸ“± Mobile Support #### The viewer is fully responsive and works on mobile devices: ##### Touch gestures for scrolling ##### Pinch to zoom (PDF) ##### Responsive toolbar ##### Optimized for small screens ##### šŸ”’ Security ##### Sanitizes HTML content for Word documents ##### Validates file types ##### Secure handling of file sources ##### No external dependencies for sensitive operations ### šŸ› Troubleshooting ##### Issue: PDF not loading ##### Solution: Ensure PDF.js is properly loaded: #### šŸ™ Acknowledgments ##### PDF.js - PDF rendering ##### Mammoth.js - Word document conversion ##### SheetJS - Excel file processing ### šŸ“ž Support ##### For support, email abhishekrout128@gmail.com..