-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mikecousins
Author
Owner
|
||
}, | ||
"peerDependencies": { | ||
This comment has been minimized.
Sorry, something went wrong.
MichaelDeBoey
Contributor
|
||
"prop-types": "^15.5.4", | ||
"react": "^15.0.0 || ^16.0.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className={styles.test}> | ||
Example Component: {text} | ||
</div> | ||
) | ||
render() { | ||
return <canvas id="pdf-canvas" />; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
[email protected]: | ||
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" | ||
|
I think it's best to make this a caret (
^
) like