-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds/modifies examples for node.js and webpack.
- Loading branch information
1 parent
9228e1f
commit 0f095a1
Showing
15 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Overview | ||
|
||
Example to demonstrate PDF.js library usage with webpack. | ||
|
||
## Getting started | ||
|
||
Build project and install the example dependencies: | ||
|
||
$ node make dist | ||
$ cd examples/webpack | ||
$ npm install | ||
|
||
To build webpack bundles, run `node_modules/.bin/webpack`. If you are running | ||
a web server, you can observe the build results at | ||
http://localhost:8888/examples/webpack/index.html | ||
|
||
See main.js and webpack.config.js files. Please notice that PDF.js packaging | ||
requires 'entry' loader. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>webpack example</title> | ||
<script src="../../build/webpack/bundle.js"></script> | ||
</head> | ||
<body> | ||
<canvas id="theCanvas"></canvas> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/licenses/publicdomain/ | ||
|
||
// Hello world example for webpack. | ||
|
||
require('pdfjs-dist'); | ||
|
||
var pdfPath = '../helloworld/helloworld.pdf'; | ||
|
||
// It is also possible to disable workers via `PDFJS.disableWorker = true` | ||
|
||
// Loading a documents. | ||
var loadingTask = PDFJS.getDocument(pdfPath); | ||
loadingTask.promise.then(function (pdfDocument) { | ||
// Getting a first page | ||
return pdfDocument.getPage(1).then(function (pdfPage) { | ||
// Display page on the existing canvas with 100% scale. | ||
var viewport = pdfPage.getViewport(1.0); | ||
var c = document.getElementById('theCanvas'); | ||
c.width = viewport.width; | ||
c.height = viewport.height; | ||
var ctx = c.getContext('2d'); | ||
var renderTask = pdfPage.render({ | ||
canvasContext: ctx, | ||
viewport: viewport | ||
}); | ||
return renderTask.promise; | ||
}); | ||
}).catch(function (reason) { | ||
console.error('Error: ' + reason); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "webpack-pdf.js-example", | ||
"version": "0.1.0", | ||
"devDependencies": { | ||
"webpack": "~1.12.9", | ||
"entry-loader": "~0.1.0", | ||
"pdfjs-dist": "../../build/dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var webpack = require('webpack'); | ||
var path = require("path"); | ||
|
||
module.exports = { | ||
context: __dirname, | ||
entry: "./main.js", | ||
output: { | ||
path: path.join(__dirname, "../../build/webpack"), | ||
publicPath: '../../build/webpack/', | ||
filename: "bundle.js" | ||
}, | ||
plugins: [ | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compressor: { | ||
screw_ie8: true, | ||
warnings: false | ||
} | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// included from api.js for GENERIC build | ||
|
||
/*jshint globalstrict: false */ | ||
/* globals PDFJS, require, module */ | ||
|
||
var useRequireEnsure = false; | ||
if (typeof module !== 'undefined' && module.require) { | ||
// node.js - disable worker and set require.ensure. | ||
PDFJS.disableWorker = true; | ||
if (typeof require.ensure === 'undefined') { | ||
require.ensure = require('node-ensure'); | ||
} | ||
useRequireEnsure = true; | ||
} | ||
if (typeof __webpack_require__ !== 'undefined') { | ||
// Webpack - get/bundle pdf.worker.js as additional file. | ||
PDFJS.workerSrc = require('entry?name=[hash]-worker.js!./pdf.worker.js'); | ||
useRequireEnsure = true; | ||
} | ||
var fakeWorkerFilesLoader = useRequireEnsure && function (callback) { | ||
'use strict'; | ||
require.ensure([], function () { | ||
require('./pdf.worker.js'); | ||
callback(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters