From a18caa730d0ba80bbd18c213ac327479d737d7bb Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Wed, 10 May 2017 18:28:18 -0500 Subject: [PATCH] Adds gulp dist-install command; using pdfjs-dist package in examples. --- README.md | 2 ++ examples/acroforms/acroforms.html | 6 +++--- examples/acroforms/acroforms.js | 2 +- examples/browserify/README.md | 2 +- examples/browserify/package.json | 2 +- examples/components/pageviewer.html | 6 +++--- examples/components/pageviewer.js | 6 +++--- examples/components/simpleviewer.html | 6 +++--- examples/components/simpleviewer.js | 6 +++--- examples/helloworld/hello.js | 7 ++++--- examples/learning/helloworld.html | 6 +++--- examples/learning/helloworld64.html | 4 ++-- examples/learning/prevnext.html | 4 ++-- examples/mobile-viewer/viewer.html | 6 +++--- examples/mobile-viewer/viewer.js | 6 +++--- examples/node/getinfo.js | 4 ++-- examples/node/pdf2png/pdf2png.js | 2 +- examples/node/pdf2svg.js | 4 ++-- examples/svgviewer/viewer.js | 9 +++++---- examples/text-only/index.html | 2 +- examples/text-only/pdf2svg.js | 4 ++-- examples/webpack/README.md | 2 +- examples/webpack/package.json | 5 ++++- gulpfile.js | 20 +++++++++++++++----- 24 files changed, 70 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 0db3f4c02..017fd60a4 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ The repository contains a hello world example that you can run locally: + [examples/helloworld/](https://github.com/mozilla/pdf.js/blob/master/examples/helloworld/) +More examples can be found at the examples folder. Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via `gulp dist-install` command. + For an introduction to the PDF.js code, check out the presentation by our contributor Julian Viereck: diff --git a/examples/acroforms/acroforms.html b/examples/acroforms/acroforms.html index bba3a7755..7768d2b75 100644 --- a/examples/acroforms/acroforms.html +++ b/examples/acroforms/acroforms.html @@ -20,10 +20,10 @@ limitations under the License. AcroForms example - + - - + + - + - - + + diff --git a/examples/components/pageviewer.js b/examples/components/pageviewer.js index 54e1dceb2..0c4899137 100644 --- a/examples/components/pageviewer.js +++ b/examples/components/pageviewer.js @@ -17,16 +17,16 @@ if (!PDFJS.PDFViewer || !PDFJS.getDocument) { alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist`'); + ' `gulp dist-install`'); } // The workerSrc property shall be specified. // -PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js'; +PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js'; // Some PDFs need external cmaps. // -// PDFJS.cMapUrl = '../../build/dist/cmaps/'; +// PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/'; // PDFJS.cMapPacked = true; var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; diff --git a/examples/components/simpleviewer.html b/examples/components/simpleviewer.html index 692d1ee04..e2ac0e92b 100644 --- a/examples/components/simpleviewer.html +++ b/examples/components/simpleviewer.html @@ -35,10 +35,10 @@ limitations under the License. } - + - - + + diff --git a/examples/components/simpleviewer.js b/examples/components/simpleviewer.js index 60438a467..5fe597b5b 100644 --- a/examples/components/simpleviewer.js +++ b/examples/components/simpleviewer.js @@ -17,16 +17,16 @@ if (!PDFJS.PDFViewer || !PDFJS.getDocument) { alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist`'); + ' `gulp dist-install`'); } // The workerSrc property shall be specified. // -PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js'; +PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js'; // Some PDFs need external cmaps. // -// PDFJS.cMapUrl = '../../build/dist/cmaps/'; +// PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/'; // PDFJS.cMapPacked = true; var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; diff --git a/examples/helloworld/hello.js b/examples/helloworld/hello.js index b4421b6d0..484597920 100644 --- a/examples/helloworld/hello.js +++ b/examples/helloworld/hello.js @@ -1,12 +1,13 @@ 'use strict'; // In production, the bundled pdf.js shall be used instead of SystemJS. -Promise.all([SystemJS.import('pdfjs/display/api'), - SystemJS.import('pdfjs/display/global')]) +Promise.all([System.import('pdfjs/display/api'), + System.import('pdfjs/display/global'), + System.resolve('pdfjs/worker_loader')]) .then(function (modules) { var api = modules[0], global = modules[1]; // In production, change this to point to the built `pdf.worker.js` file. - global.PDFJS.workerSrc = '../../src/worker_loader.js'; + global.PDFJS.workerSrc = modules[2]; // Fetch the PDF document from the URL using promises. api.getDocument('helloworld.pdf').then(function (pdf) { diff --git a/examples/learning/helloworld.html b/examples/learning/helloworld.html index 685cccd76..c7e76766e 100644 --- a/examples/learning/helloworld.html +++ b/examples/learning/helloworld.html @@ -11,9 +11,9 @@ - + - + + + - + + diff --git a/examples/mobile-viewer/viewer.js b/examples/mobile-viewer/viewer.js index 5e734684a..a44cb3bd8 100644 --- a/examples/mobile-viewer/viewer.js +++ b/examples/mobile-viewer/viewer.js @@ -18,14 +18,14 @@ if (!PDFJS.PDFViewer || !PDFJS.getDocument) { alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist`'); + ' `gulp dist-install`'); } PDFJS.useOnlyCssZoom = true; PDFJS.disableTextLayer = true; PDFJS.maxImageSize = 1024 * 1024; -PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js'; -PDFJS.cMapUrl = '../../build/dist/cmaps/'; +PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js'; +PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/'; PDFJS.cMapPacked = true; var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; diff --git a/examples/node/getinfo.js b/examples/node/getinfo.js index 3bed39297..1e91f586a 100644 --- a/examples/node/getinfo.js +++ b/examples/node/getinfo.js @@ -12,8 +12,8 @@ var fs = require('fs'); // HACK adding DOMParser to read XMP metadata. global.DOMParser = require('./domparsermock.js').DOMParserMock; -// Run `gulp dist` to generate 'pdfjs-dist' npm package files. -var pdfjsLib = require('../../build/dist'); +// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. +var pdfjsLib = require('pdfjs-dist'); // Loading file from file system into typed array var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; diff --git a/examples/node/pdf2png/pdf2png.js b/examples/node/pdf2png/pdf2png.js index b595861d0..873fcc90f 100644 --- a/examples/node/pdf2png/pdf2png.js +++ b/examples/node/pdf2png/pdf2png.js @@ -48,7 +48,7 @@ NodeCanvasFactory.prototype = { }, }; -var pdfjsLib = require('../../../build/dist'); +var pdfjsLib = require('pdfjs-dist'); // Relative path of the PDF file. var pdfURL = '../../helloworld/helloworld.pdf'; diff --git a/examples/node/pdf2svg.js b/examples/node/pdf2svg.js index b9ce96b6f..7edf5df32 100644 --- a/examples/node/pdf2svg.js +++ b/examples/node/pdf2svg.js @@ -10,8 +10,8 @@ var fs = require('fs'); // HACK few hacks to let PDF.js be loaded not as a module in global space. require('./domstubs.js'); -// Run `gulp dist` to generate 'pdfjs-dist' npm package files. -var pdfjsLib = require('../../build/dist'); +// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. +var pdfjsLib = require('pdfjs-dist'); // Loading file from file system into typed array var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; diff --git a/examples/svgviewer/viewer.js b/examples/svgviewer/viewer.js index 3a5a831b6..ae10ad6f4 100644 --- a/examples/svgviewer/viewer.js +++ b/examples/svgviewer/viewer.js @@ -36,13 +36,14 @@ function renderDocument(pdf, svgLib) { } } -Promise.all([SystemJS.import('pdfjs/display/api'), - SystemJS.import('pdfjs/display/svg'), - SystemJS.import('pdfjs/display/global')]) +Promise.all([System.import('pdfjs/display/api'), + System.import('pdfjs/display/svg'), + System.import('pdfjs/display/global'), + System.resolve('pdfjs/worker_loader')]) .then(function (modules) { var api = modules[0], svg = modules[1], global = modules[2]; // In production, change this to point to the built `pdf.worker.js` file. - global.PDFJS.workerSrc = '../../src/worker_loader.js'; + global.PDFJS.workerSrc = modules[3]; // In production, change this to point to where the cMaps are placed. global.PDFJS.cMapUrl = '../../external/bcmaps/'; diff --git a/examples/text-only/index.html b/examples/text-only/index.html index df1d607dd..2717dcb07 100644 --- a/examples/text-only/index.html +++ b/examples/text-only/index.html @@ -3,7 +3,7 @@ Text-only PDF.js example - + diff --git a/examples/text-only/pdf2svg.js b/examples/text-only/pdf2svg.js index c808db44c..ca7cf8183 100644 --- a/examples/text-only/pdf2svg.js +++ b/examples/text-only/pdf2svg.js @@ -18,7 +18,7 @@ var PAGE_NUMBER = 1; var PAGE_SCALE = 1.5; var SVG_NS = 'http://www.w3.org/2000/svg'; -PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js'; +PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js'; function buildSVG(viewport, textContent) { // Building SVG with size of the viewport (for simplicity) @@ -63,7 +63,7 @@ function pageLoaded() { document.addEventListener('DOMContentLoaded', function () { if (typeof PDFJS === 'undefined') { alert('Built version of PDF.js was not found.\n' + - 'Please run `gulp generic`.'); + 'Please run `gulp dist-install`.'); return; } pageLoaded(); diff --git a/examples/webpack/README.md b/examples/webpack/README.md index 3a7ce9eb1..0799b98df 100644 --- a/examples/webpack/README.md +++ b/examples/webpack/README.md @@ -6,7 +6,7 @@ Example to demonstrate PDF.js library usage with Webpack. Build project and install the example dependencies: - $ gulp dist + $ gulp dist-install $ cd examples/webpack $ npm install diff --git a/examples/webpack/package.json b/examples/webpack/package.json index 085fcd261..c2eaabe02 100644 --- a/examples/webpack/package.json +++ b/examples/webpack/package.json @@ -1,8 +1,11 @@ { "name": "webpack-pdf.js-example", "version": "0.1.0", + "scripts": { + "build": "webpack" + }, "devDependencies": { "webpack": "~1.12.9", - "pdfjs-dist": "../../build/dist" + "pdfjs-dist": "../../node_modules/pdfjs-dist" } } diff --git a/gulpfile.js b/gulpfile.js index 7d47fd8dd..eb6c99298 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1031,9 +1031,6 @@ gulp.task('lib', ['buildnumber'], function () { gulp.task('web-pre', ['generic', 'extension', 'jsdoc']); -gulp.task('dist-pre', - ['generic', 'singlefile', 'components', 'lib', 'minified']); - gulp.task('publish', ['generic'], function (done) { var version = JSON.parse( fs.readFileSync(BUILD_DIR + 'version.json').toString()).version; @@ -1262,7 +1259,9 @@ gulp.task('gh-pages-git', ['gh-pages-prepare', 'wintersmith'], function () { gulp.task('web', ['gh-pages-prepare', 'wintersmith', 'gh-pages-git']); -gulp.task('dist-repo-prepare', ['dist-pre'], function () { +gulp.task('dist-pre', + ['generic', 'singlefile', 'components', 'lib', 'minified'], + function () { var VERSION = getVersionJSON().version; console.log(); @@ -1355,7 +1354,18 @@ gulp.task('dist-repo-prepare', ['dist-pre'], function () { ]); }); -gulp.task('dist-repo-git', ['dist-repo-prepare'], function () { +gulp.task('dist-install', ['dist-pre'], function () { + var distPath = DIST_DIR; + var opts = {}; + var installPath = process.env['PDFJS_INSTALL_PATH']; + if (installPath) { + opts.cwd = installPath; + distPath = path.relative(installPath, distPath); + } + safeSpawnSync('npm', ['install', distPath], opts); +}); + +gulp.task('dist-repo-git', ['dist-pre'], function () { var VERSION = getVersionJSON().version; console.log();