React PDF Viewer component using PDF.js (setup the iframe url by https://gist.github.com/vinhlh/22c92f1a9f4fdb72fdbabefee34cef4d)
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