Skip to main content
The Document Preview component provides an embedded viewer for various document formats with navigation, zoom, and download capabilities.

Basic usage

<flx-document-preview
  [src]="documentUrl"
  [type]="documentType">
</flx-document-preview>

Properties

src
string
required
URL or data URI of the document to preview
type
'pdf' | 'image' | 'text' | 'auto'
default:"auto"
Type of document. Set to ‘auto’ to detect from file extension
height
string
default:"600px"
Height of the preview container
showToolbar
boolean
default:"true"
Shows toolbar with controls
showDownload
boolean
default:"true"
Shows download button in toolbar
showPrint
boolean
default:"true"
Shows print button in toolbar
showZoom
boolean
default:"true"
Shows zoom controls
showNavigation
boolean
default:"true"
Shows page navigation for multi-page documents
initialZoom
number
default:"1"
Initial zoom level (1 = 100%)
fileName
string
Name of the file for download

Events

load
EventEmitter<void>
Emitted when document finishes loading
error
EventEmitter<Error>
Emitted when document fails to load
pageChange
EventEmitter<number>
Emitted when current page changes

Examples

<flx-document-preview
  [src]="pdfUrl"
  type="pdf"
  height="800px"
  fileName="document.pdf">
</flx-document-preview>
export class PDFViewer {
  pdfUrl = '/assets/documents/report.pdf';
}

Supported formats

The Document Preview component supports:
  • PDF: Full-featured PDF viewer with navigation and zoom
  • Images: JPG, PNG, GIF, SVG, WebP
  • Text: Plain text files (TXT, CSV, JSON, XML)
For security reasons, the component does not support executable files or scripts. Microsoft Office formats (DOC, XLS, PPT) require server-side conversion to PDF.

Styling

flx-document-preview {
  --flx-preview-background: #f3f4f6;
  --flx-preview-toolbar-background: #ffffff;
  --flx-preview-toolbar-height: 48px;
  --flx-preview-border-color: #d1d5db;
  --flx-preview-button-color: #374151;
  --flx-preview-button-hover-background: #f3f4f6;
}

Best practices

  • Always provide a fileName for better download experience
  • Set appropriate height based on your layout
  • Handle load errors gracefully with fallback UI
  • Use loading indicators while documents load
  • Consider file size limits for client-side rendering
  • For sensitive documents, ensure proper authentication
  • Test with various document types and sizes
For large PDF files, consider showing a loading indicator and implementing progressive loading or thumbnail previews.

Accessibility

  • PDF content maintains document accessibility features
  • Keyboard navigation support (arrow keys, page up/down)
  • Focus management for toolbar controls
  • Screen reader compatible
  • Alternative text for images
  • File Upload - For uploading documents
  • Modal - For full-screen document viewing

Build docs developers (and LLMs) love