#!/bin/sh set -eu # This script fetches the latest build of PDF.js from the viewer demo # page. # # See https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website#from-examples # # To update PDF.js to the latest version: # # 1. Create a new branch and run this script. This will fetch the latest PDF.js # release and commit the changes. # 2. Check that PDF annotation works as expected. See the project README for # steps to run this locally. DEST_DIR=viewer/ # PDF.js comes in two flavors, one for modern browsers and one for older browsers, # known as the "legacy" build. # # The versions supported by the legacy build are listed at # https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#which-browsers-are-supported # and as of September 2021 these align closely with what the client supports # (see https://github.com/hypothesis/client/issues/3744). # # In the extracted tarball, the modern version is in pdf.js-gh-pages/ and the # legacy version is in pdf.js-gh-pages/legacy/. PREFIX=pdf.js-gh-pages/legacy PREFIX_DEPTH=2 COMPONENTS="$PREFIX/build $PREFIX/web $PREFIX/LICENSE" # Download the latest version of the PDF.js library and viewer. rm -rf $DEST_DIR mkdir -p $DEST_DIR # Get the latest build of the viewer curl -L https://github.com/mozilla/pdf.js/archive/gh-pages.tar.gz \ | tar -xz --directory $DEST_DIR --strip-components=$PREFIX_DEPTH $COMPONENTS # Remove the check that the PDF being loaded is from the same origin as the # viewer. sed -i '' -e 's/HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)/true \/* Hypothesis *\//' $DEST_DIR/web/viewer.js # Modify the viewer HTML page to load the Hypothesis client. cp pdfjs-init.js $DEST_DIR/web/ sed -i '' -e 's/<\/head>/