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).
Project information
- Project categories: Content display
51 sites report using this module
- Created by mouhammed on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
Releases
Rewrite for Drupal 10.3/11 (PDF.js previews). Alpha3 adds drush viewerjs:install-library to download PDF.js.
Development version: 2.0.x-dev updated 26 Oct 2026 at 20:01 UTC

