Modern web applications require a smooth and secure way to preview files such as PDFs, images, videos, and DOCX documents. Traditionally, developers use the <iframe> tag to embed these files. However, iframes come with problems like poor mobile support, browser restrictions, limited styling, and cross-origin issues.
This article explains how to build a fully custom file viewer in Angular without using any iframe, using native HTML elements and specialised libraries.
Objective of This Article
Build a unified file viewer in Angular
Support PDF, images, videos, and DOCX
Avoid
<iframe>completelyProvide clean UI and modular code
Deliver a reusable component that works in any Angular project
Overall Architecture
Architecture Diagram (Visio-Style)
+-----------------------------+
| Angular App |
+-----------------------------+
| Requests File
v
+--------------------------------+
| File Viewer Component |
+--------------------------------+
| | | |
| | | |
v v v v
+--------+ +-------+ +------+ +---------+
| PDF | | Image | | Video | | DOCX |
| Rendering| | Viewer| | Player| | Viewer |
+----------+ +-------+ +------+ +---------+
|
| requests binary file
v
+------------------------------+
| ASP.NET Core Backend |
| (File fetch, binary output) |
+------------------------------+
|
v
+------------------------------+
| SQL Server / Storage |
+------------------------------+
ER Diagram (Storage Structure)
Most systems store metadata only and the file itself in disk/cloud.
+----------------------------+
| FileMeta |
+----------------------------+
| FileId (PK) |
| FileName |
| FileType |
| FileSize |
| StoragePath |
| UploadedBy |
| UploadedOn |
+----------------------------+
Workflow Diagram
User selects file
|
v
Angular component detects file type
|
+--> PDF? -----> Render using pdf-lib / pdfjs-dist
|
+--> Image? -----> Render using <img> tag
|
+--> Video? -----> Render using <video> tag
|
+--> DOCX? -----> Convert to HTML using docx-preview
and display in custom container
Flowchart
+---------------------+
| Load file metadata |
+---------------------+
|
v
+--------------------------+
| Identify file extension |
+--------------------------+
.----------|-----------|-----------|-----------.
v v v v v
+--------+ +--------+ +----------+ +----------+ +--------+
| PDF | | Image | | Video | | DOCX | | Others |
+--------+ +--------+ +----------+ +----------+ +--------+
| | | | |
Render PDF Show <img> Show <video> Convert DOCX Show error/
component tag tag to HTML download-only
Sequence Diagram (File Rendering)
User ----> Angular Component: Request to open file
Angular Component ----> Backend API: Fetch file binary
Backend API ----> Storage: Read file
Storage ----> Backend API: Return file stream
Backend API ----> Angular Component: Binary file + metadata
Angular Component ----> FileViewerService: Detect file type
FileViewerService ----> Angular Components: Render appropriate viewer

Join the conversation! Your thoughts help the community grow.