Created
May 22, 2016 08:11
-
-
Save vinhlh/1d285f20bd909a9a3efd85161fdd1ab8 to your computer and use it in GitHub Desktop.
React PDF Viewer component using PDF.js (setup the iframe url by https://gist.github.com/vinhlh/22c92f1a9f4fdb72fdbabefee34cef4d)
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
import React, { Component, PropTypes } from 'react' | |
import { PDF_VIEWER } from '../configs' | |
const propTypes = { | |
ratio : PropTypes.number, | |
file : PropTypes.string.isRequired | |
} | |
const defaultProps = { | |
ratio: 56.25 | |
} | |
class PdfViewer extends Component { | |
shouldComponentUpdate(newProps) { | |
return this.props.file != newProps.file | |
} | |
render() { | |
const { ratio, file } = this.props | |
return ( | |
<div className="pdf-viewer" style={{ paddingBottom: `${ratio}%` }} content="Loading"> | |
<iframe src={`${PDF_VIEWER}?file=${file}`} /> | |
</div> | |
) | |
} | |
} | |
PdfViewer.propTypes = propTypes | |
PdfViewer.defaultProps = defaultProps | |
export default PdfViewer |
Author
vinhlh
commented
May 22, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment