Images
Show PNG, JPEG, GIF, WebP, AVIF, BMP, ICO, SVG, TIFF, HEIC and EMF/WMF images in React, with zoom, rotation and multi-page TIFF scans.
| Format | How it is drawn |
|---|---|
| PNG, JPEG, GIF, WebP, AVIF, BMP, ICO | The browser's own decoders. |
| SVG | As an image, so scripts inside the file never run. |
| TIFF | Our own decoder, in every browser. |
| HEIC, HEIF | Safari natively. Elsewhere our HEIF reader passes the tiles to the browser's HEVC decoder (WebCodecs), available in Chrome and Edge on systems with HEVC support; other browsers show a clear message. |
| EMF, WMF | Our own metafile interpreter, converting to SVG. |
TIFF
Strips and tiles; no compression, LZW, Deflate, PackBits, CCITT G3 and G4 fax and JPEG; predictors; 1 to 16 bits per sample; palette, CMYK, CIE L*a*b* and alpha; planar data; BigTIFF and orientation. Multi-page files show as pages with thumbnails, and print at their scanned size when the file states a resolution.
EMF and WMF
Shapes, paths, pens and brushes (hatches and patterns too), text with per-character spacing, Symbol-font maths, clipping, world transforms, gradients, bitmaps, and WMF embedded in EMF. The same interpreter draws metafile pictures inside Word, Excel and PowerPoint files. Pictures stored only as EMF+ (GDI+) are not drawn yet.
Controller
| State | For images | For TIFF |
|---|---|---|
page, pageCount | No pages (pageCount 0). | 'page', the page in view and the number of pages. |
zoom, scale | Every zoom, fit modes included. 'actual' is one image pixel per CSS pixel. | Same. |
rotation | 0, 90, 180 or 270. | Same, for every page. |
thumbnails | None. | One per page. |
outline | None. | None. |
search | Not searchable (can.search false). | Not searchable. |
can | zoom, fit, rotate, print, download. | zoom, fit, rotate, print, download, sidebar. |
Headless
An image viewer with a zoom slider, fit and actual size, rotation, and page thumbnails that appear only for multi-page files:
'use client';
// An image viewer: zoom slider, fit and actual size, rotation. Multi-page TIFF scans also get
// page navigation and thumbnails; other images have pageCount 0 and no thumbnails.
import { DocumentSurface, Thumbnail, useDocViewer, useThumbnails, type DocSource } from '@anypreview/react';
import '@anypreview/react/styles.css';
export default function ImageViewer({ source }: { source: DocSource }) {
const viewer = useDocViewer({ source, defaultZoom: 'fit-page' });
const pages = useThumbnails(viewer);
return (
<div className="flex h-full flex-col text-sm">
<header className="flex flex-wrap items-center gap-3 border-b p-2">
<input
type="range"
aria-label="Zoom"
min={0.1}
max={4}
step={0.05}
value={viewer.scale}
onChange={(e) => viewer.setZoom(Number(e.target.value))}
/>
<span>{Math.round(viewer.scale * 100)}%</span>
<button onClick={() => viewer.setZoom('fit-page')}>Fit</button>
<button onClick={() => viewer.setZoom('actual')}>100%</button>
{viewer.can.rotate && <button onClick={viewer.rotate}>Rotate</button>}
{viewer.pageCount > 1 && (
<span>
Page {viewer.page} of {viewer.pageCount}
</span>
)}
<button className="ml-auto" onClick={viewer.download}>Download</button>
</header>
<div className="flex min-h-0 flex-1">
{pages && pages.count > 1 && (
<nav className="w-32 shrink-0 overflow-y-auto border-r p-2">
{Array.from({ length: pages.count }, (_, i) => (
<button key={i} className="mb-2 block" onClick={() => viewer.goTo(i + 1)}>
<Thumbnail viewer={viewer} index={i} width={100} />
</button>
))}
</nav>
)}
<DocumentSurface viewer={viewer} className="min-w-0 flex-1" />
</div>
</div>
);
}Markdown, code and notebooks
Show Markdown, source code in 200+ languages, plain text, huge logs and Jupyter notebooks in React, with highlighting, search and printing.
Email and ZIP archives
Show EML and Outlook MSG emails with attachments, and browse ZIP archives, in React. Attachments and archive entries open in a nested viewer.