NG Universal File Previewer
July 11, 2025 ยท View on GitHub
A powerful, universal file previewer library for Angular applications with support for PDF, images, documents, spreadsheets, and more.
โจ Features
- ๐ PDF Preview with page navigation and zoom controls
- ๐ผ๏ธ Image Preview with zoom and full-size view
- ๐ Excel/CSV data table preview
- ๐ Word Document preview (DOCX)
- ๐จ Modern UI with light/dark theme support
- ๐ฑ Responsive Design - works on mobile and desktop
- ๐ง Highly Configurable with custom processors
- ๐ Easy Integration - just add one component
Live Demo
๐ Quick Start
Installation
npm install ng-universal-file-previewer
Import the Module
import { NgUniversalFilePreviewerModule } from 'ng-universal-file-previewer';
@NgModule({
imports: [
NgUniversalFilePreviewerModule
]
})
export class AppModule { }
Basic Usage
<ngx-file-previewer
[config]="previewConfig"
[theme]="'light'"
(fileSelected)="onFileSelected($event)"
(previewReady)="onPreviewReady($event)">
</ngx-file-previewer>
export class AppComponent {
previewConfig = {
maxFileSize: 10 * 1024 * 1024, // 10MB
supportedTypes: ['pdf', 'image', 'docx', 'xlsx', 'csv', 'txt'],
autoPreview: true
};
onFileSelected(file: File) {
console.log('File selected:', file.name);
}
onPreviewReady(result: any) {
console.log('Preview ready:', result);
}
}
๐ Documentation
Supported File Types
- PDF: Full rendering with page navigation and zoom
- Images: PNG, JPEG, GIF, WebP, SVG
- Documents: DOCX (with full content rendering)
- Spreadsheets: XLSX, XLS, CSV
- Text: TXT, JSON, HTML, XML
Configuration Options
interface FilePreviewConfig {
maxFileSize: number; // Maximum file size in bytes
supportedTypes: FileType[]; // Array of supported file types
autoPreview: boolean; // Auto-generate preview on file selection
showFileInfo: boolean; // Show file information panel
}
Theming
The library supports both light and dark themes:
<ngx-file-previewer [theme]="'dark'"></ngx-file-previewer>
Custom Styling
Add custom CSS classes:
<ngx-file-previewer [customClass]="'my-custom-preview'"></ngx-file-previewer>
๐ง Advanced Usage
Custom File Processors
import { FileProcessorService } from 'ng-universal-file-previewer';
constructor(private fileProcessor: FileProcessorService) {
// Register custom processor for a file type
this.fileProcessor.registerCustomProcessor('custom', async (file: File) => {
return '<div>Custom preview content</div>';
});
}
๐ฆ Dependencies
@angular/core(^17.0.0)@angular/common(^17.0.0)pdfjs-dist(^3.4.120)mammoth(^1.6.0)xlsx(^0.18.5)
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
MIT License - see LICENSE file for details.
๐ Issues
Report issues on GitHub Issues