diff --git a/example/public/test.pdf b/example/public/test.pdf
new file mode 100644
index 00000000..199fbfca
Binary files /dev/null and b/example/public/test.pdf differ
diff --git a/example/src/App.js b/example/src/App.js
index 2bd8c76b..881c9ef6 100644
--- a/example/src/App.js
+++ b/example/src/App.js
@@ -1,12 +1,12 @@
import React, { Component } from 'react'
-import ExampleComponent from 'react-pdf-js'
+import Pdf from 'react-pdf-js'
export default class App extends Component {
render () {
return (
)
}
diff --git a/package.json b/package.json
index 5bc6b230..1f2aa1cf 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,9 @@
"predeploy": "cd example && yarn install && yarn run build",
"deploy": "gh-pages -d example/build"
},
- "dependencies": {},
+ "dependencies": {
+ "pdfjs-dist": "2.0.550"
+ },
"peerDependencies": {
"prop-types": "^15.5.4",
"react": "^15.0.0 || ^16.0.0",
diff --git a/src/index.js b/src/index.js
index dee1b6cc..a6c04084 100755
--- a/src/index.js
+++ b/src/index.js
@@ -1,26 +1,37 @@
/**
- * @class ExampleComponent
+ * @class ReactPdfJs
*/
-
import React, { Component } from 'react'
import PropTypes from 'prop-types'
+import PdfJsLib from 'pdfjs-dist';
-import styles from './styles.css'
-
-export default class ExampleComponent extends Component {
+export default class ReactPdfJs extends Component {
static propTypes = {
- text: PropTypes.string
+ file: PropTypes.string
}
- render() {
- const {
- text
- } = this.props
+ componentDidMount() {
+ PdfJsLib.GlobalWorkerOptions.workerSrc = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.550/pdf.worker.js';
+ PdfJsLib.getDocument(this.props.file).then((pdf) => {
+ pdf.getPage(1).then((page) => {
+ var scale = 1.5;
+ var viewport = page.getViewport(scale);
+
+ var canvas = document.getElementById('pdf-canvas');
+ var context = canvas.getContext('2d');
+ canvas.height = viewport.height;
+ canvas.width = viewport.width;
+
+ var renderContext = {
+ canvasContext: context,
+ viewport: viewport
+ };
+ page.render(renderContext);
+ });
+ });
+ }
- return (
-
- Example Component: {text}
-
- )
+ render() {
+ return ;
}
}
diff --git a/yarn.lock b/yarn.lock
index dee6a053..c59e7520 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -145,7 +145,7 @@ ajv-keywords@^2.0.0, ajv-keywords@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762"
-ajv-keywords@^3.0.0:
+ajv-keywords@^3.0.0, ajv-keywords@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.2.0.tgz#e86b819c602cf8821ad637413698f1dec021847a"
@@ -158,7 +158,7 @@ ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.0, ajv@^5.2.3, ajv@^5.3.0:
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"
-ajv@^6.0.1:
+ajv@^6.0.1, ajv@^6.1.0:
version "6.5.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.5.1.tgz#88ebc1263c7133937d108b80c5572e64e1d9322d"
dependencies:
@@ -4695,7 +4695,7 @@ loader-utils@^0.2.16:
json5 "^0.5.0"
object-assign "^4.0.1"
-loader-utils@^1.0.2, loader-utils@^1.1.0:
+loader-utils@^1.0.0, loader-utils@^1.0.2, loader-utils@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
dependencies:
@@ -5085,6 +5085,10 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"
+node-ensure@^0.0.0:
+ version "0.0.0"
+ resolved "https://registry.yarnpkg.com/node-ensure/-/node-ensure-0.0.0.tgz#ecae764150de99861ec5c810fd5d096b183932a7"
+
node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
@@ -5525,6 +5529,13 @@ pbkdf2@^3.0.3:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
+pdfjs-dist@2.0.550:
+ version "2.0.550"
+ resolved "https://registry.yarnpkg.com/pdfjs-dist/-/pdfjs-dist-2.0.550.tgz#52a5bd05d8b250206ccd2843209cfa3b8f1ea4ae"
+ dependencies:
+ node-ensure "^0.0.0"
+ worker-loader "^2.0.0"
+
performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -6612,6 +6623,13 @@ schema-utils@^0.3.0:
dependencies:
ajv "^5.0.0"
+schema-utils@^0.4.0:
+ version "0.4.5"
+ resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.5.tgz#21836f0608aac17b78f9e3e24daff14a5ca13a3e"
+ dependencies:
+ ajv "^6.1.0"
+ ajv-keywords "^3.1.0"
+
select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
@@ -7730,6 +7748,13 @@ worker-farm@^1.3.1:
dependencies:
errno "~0.1.7"
+worker-loader@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-2.0.0.tgz#45fda3ef76aca815771a89107399ee4119b430ac"
+ dependencies:
+ loader-utils "^1.0.0"
+ schema-utils "^0.4.0"
+
wrap-ansi@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"