-
-
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" />; | ||
} | ||
} |
I think it's best to make this a caret (
^
) like