import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './app.css';
import {DsPdfViewer} from '@mescius/dspdfviewer';
import '/diodocs/pdfviewer/demos/resource/js/init.js';
class App extends React.Component {
_viewer;
constructor(props) {
super(props);
}
componentDidMount() {
const root = ReactDOM.findDOMNode(this);
const viewer = new DsPdfViewer(root, {
workerSrc: "/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.worker.js",
cMapUrl: "/diodocs/pdfviewer/demos/product-bundles/build/resources/bcmaps/",
restoreViewStateOnLoad: false
});
viewer.addDefaultPanels();
viewer.open("/diodocs/pdfviewer/demos/product-bundles/assets/pdf/helloworld.pdf");
this._viewer = viewer;
}
componentWillUnmount() {
if(this._viewer) {
this._viewer.dispose();
this._viewer = null;
}
}
render(){
return <div id="viewer"></div>
}
}
ReactDOM.render(<App />, document.getElementById('app'));
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PDFの表示 (React)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SystemJS -->
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app');
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
#app {
height: 100%;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/dspdfviewer': 'npm:@mescius/dspdfviewer/dspdfviewer.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);