Destroyed Setup PDF.js in a website (Linux) (mediawiki)

Tim van der Meij 2015-08-04 21:57:58 +02:00
parent 2b26e6b4e2
commit 2147a377e0

@ -1,84 +0,0 @@
Note that the instructions on this page are focussed on Debian, Ubuntu and Linux Mint, but can also be applied to other Linux distributions (such as Arch Linux) with slight distribution-specific modifications (such as not using <tt>apt-get</tt> but <tt>pacman</tt> on Arch Linux).
== Setup the testing environment ==
sudo apt-get install nodejs npm
cd <website-js-dir>/
git clone git://github.com/mozilla/pdf.js.git
=== Start the test server ===
cd pdf.js/
nodejs make server
Then you can reach your Node.js server using the following URL:
http://localhost:8888/web/viewer.html
You can test your own documents by placing them into the <tt>test</tt> directory and using an URL such as:
http://localhost:8888/test/your-test-file.pdf
=== Opening PDF files from your website ===
You need to use the <tt>file</tt> parameter in the URL whose value is a full [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent encoded URI]. For example:
http://mozilla.github.com/pdf.js/web/viewer.html?file=http%3A%2F%2Fasync5.org%2Fmoz%2Fpdfjs.pdf
== Compile PDF.js ==
=== Build ===
You need to run this command:
nodejs make generic
and you should get the following output (or something similar):
### Getting extension build number
Extension build number: 331
### Bundling files into build/pdf.js
### Building localization files
### Creating generic viewer
=== Compressing PDF.js (unsupported!) ===
'''Minification is NOT supported''' by the developers of the project. First start testing with the full build and then use the minified version. From my test, the '''minified version did NOT''' work while the normal version did.
You can minify PDF.js by approximately 30% with [http://yui.github.com/yuicompressor yui-compressor] or other [http://stackoverflow.com/questions/28932/best-javascript-compressor minification tools].
==== yui-compressor Ubuntu ====
There is a package for yui-compressor on Ubuntu or Linux Mint (and other distributions):
sudo apt-get install yui-compressor
cd <pdf.js-dir>
mkdir production
yui-compressor build/pdf.js -o production/pdf-min.js # BEWARE OF UNSUPPORTED BEHAVIOR
==== Use the minified file ====
'''Minification might break the libs''' using yui-compressor. Use at your own risk.
Be sure to edit <tt>viewer.html</tt> and <tt>viewer.js</tt> to use the correct file. In this case, we want to use the minified version:
# viewer.html
<script type="text/javascript" src="./pdf-min.js"></script>
# viewer.js
PDFJS.workerSrc = './pdf-min.js';
== From build to production ==
Now that your build is done, you can copy the viewer and its resources (core files) to your production directory and upload the contents of that directory to your web server:
# make a production directory if you haven't done so already
mkdir production
# copy the viewer and its resources to the production folder
cp -R build/generic production
=== Compatibility ===
Note that you must include <tt>compatibility.js</tt> in order to support browsers like IE8+.