This guide describes how to update the pdf.js javascript library.
-
Download the latest pdf.js stable release from https://mozilla.github.io/pdf.js/getting_started/#download
-
Extract the
.zip
file -
Replace all the files and folders marked with a
*
with the corresponding ones from the new release
├── app
│ ├── assets
│ │ ├── javascripts
│ │ │ └── pdfjs_viewer
│ │ │ ├── application.js
│ │ │ ├── pdfjs
│ │ │ │ └── pdf.js *
│ │ │ ├── viewer.js *
│ │ │ └── viewer_configurations.js
│ │ └── stylesheets
│ │ └── pdfjs_viewer
│ │ ├── application.css
│ │ ├── full.scss
│ │ ├── minimal.scss
│ │ ├── pdfjs
│ │ │ └── viewer.css *
│ │ └── reduced.scss
├── public
│ └── pdfjs
│ └── web
│ ├── cmaps *
│ ├── images *
│ ├── locale *
│ └── pdf.worker.js *
- Apply the patches
Replace
var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
with
var DEFAULT_URL = window.resourceURL;
Replace
PDFJS.imageResourcesPath = './images/';
PDFJS.workerSrc = '../build/pdf.worker.js';
PDFJS.cMapUrl = '../web/cmaps/';
with
PDFJS.imageResourcesPath = '/pdfjs/web/images/';
PDFJS.workerSrc = '/pdfjs/web/pdf.worker.js?version=<version_number>';
PDFJS.cMapUrl = '/pdfjs/web/cmaps/';
The version is added as a query string above so we ensure users will get the matching version of the worker despite caching.
Replace all url(images/
with url(/pdfjs/web/images/
Take extra care here as there are a few instances of inconsistent naming across pdf.js releases! For example the upgrade to 1.10.100 was not a trivial find and replace.
Replace the whole content of app/views/pdfjs_viewer/viewer/_viewer.html.erb
with web/viewer.html
from the new pdf.js release.
Insert
<% title = local_assigns[:title] || "PDF.js viewer" %>
<% pdf_url = local_assigns[:pdf_url] %>
at the top of the file before <!DOCTYPE html>
Replace all children of <head>
except the <meta>
tags with
<%= render "pdfjs_viewer/viewer/head", title: title, pdf_url: pdf_url %>
Inject the correct styling class into the body classes.
<body tabindex="1" class="loadingInProgress" id="pdfjs_viewer-<%= style %>">
At the bottom of the file insert <%= render "pdfjs_viewer/viewer/printcontainer" %>
after <div id="printContainer"></div>