ViewerJS adds a field formatter that previews files without leaving the page. PDFs are rendered with
PDF.js in a sandboxed frame with its own toolbar (page indicator, zoom, fit width,
fullscreen, download, print); JPEG, PNG, GIF and WebP images are shown natively. Other file types get a download link.
Features
- Works with file and image fields. Choose "ViewerJS" in Manage display.
- Three modes: overlay (modal dialog), new window, or inline.
- Private files supported: previews follow Drupal file access.
- Strict Content-Security-Policy on the viewer frame, no third-party services, works offline.
- No Libraries module, no jQuery.
Requirements
- Drupal 10.3 or 11 and the core File module.
- pdfjs-dist 4.2.67 or newer in
libraries/pdfjs-dist
(see Installation;drush viewerjs:install-librarydoes it for you). Without it PDFs are download-only. The Status report shows whether it is detected.
Installation
- Install the module:
composer require drupal/viewerjs:^2.0@alphaand enable it. - Install PDF.js:
drush viewerjs:install-library. It downloadspdfjs-distfrom the npm registry, verifies its checksum and puts it inlibraries/pdfjs-dist. Run it again to update PDF.js.
Without Drush: unpack the pdfjs-dist package intolibraries/pdfjs-dist, or, if your site uses asset-packagist,composer require npm-asset/pdfjs-dist. - Check Reports > Status report for the PDF.js entry.
- If you installed PDF.js with Composer or by hand, block
libraries/pdfjs-dist/web/viewer.htmlat the web server or delete it. The module does not use it. (The Drush command never installs it.) - In Manage display of a file or image field, choose the "ViewerJS" formatter and pick the preview type (overlay, new window, inline) and size.
Versions
2.0.x (Drupal 10.3+/11) is a complete rewrite and the only supported branch. The 7.x and 8.x branches used the
abandoned ViewerJS library (bundling a 2014 PDF.js with known vulnerabilities) and are no longer supported.
Re-select the formatter when moving to 2.0.x; the color, thumbnail and template settings were removed.
Credits
Preview engine: PDF.js by Mozilla (Apache-2.0).
Ask your assistant about ViewerJS
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Release Timeline
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 2.0.0-alpha3 | Pre-release | 10–11 | Oct 26, 2026 | ||
| 2.0.0-alpha2 | Pre-release | 10–11 | Oct 26, 2026 | ||
| 2.0.x-dev | Dev | 10–11 | Oct 26, 2026 | ||
| 2.0.0-alpha1 | Pre-release | 10–11 | Oct 26, 2026 |