このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
kikikan/backend/resources/js/pages/PDFView.jsx

73 行
2.3 KiB
React
Raw 通常表示 履歴

2021-12-19 12:27:03 +09:00
import React, {useEffect, useState} from 'react';
import ReactDOM from 'react-dom';
2021-12-31 23:34:51 +09:00
import { SpecialZoomLevel, Viewer, Worker, ProgressBar} from '@react-pdf-viewer/core';
2021-12-21 08:35:53 +09:00
import { defaultLayoutPlugin } from '@react-pdf-viewer/default-layout';
import '@react-pdf-viewer/core/lib/styles/index.css';
import '@react-pdf-viewer/default-layout/lib/styles/index.css';
import { ScrollMode } from '@react-pdf-viewer/scroll-mode';
2021-12-31 23:34:51 +09:00
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";
2021-12-19 12:27:03 +09:00
const PDFViewer = () => {
const file_name = document.getElementById('pdf-url').value;
const [url, setURL] = useState('');
2021-12-21 08:35:53 +09:00
const defaultLayoutPluginInstance = defaultLayoutPlugin({
toolbarPlugin: {
fullScreenPlugin: {
onEnterFullScreen: (zoom) => {
zoom(SpecialZoomLevel.PageFit);
defaultLayoutPluginInstance.toolbarPluginInstance.scrollModePluginInstance.switchScrollMode(
ScrollMode.Wrapped
);
},
onExitFullScreen: (zoom) => {
zoom(SpecialZoomLevel.PageWidth);
defaultLayoutPluginInstance.toolbarPluginInstance.scrollModePluginInstance.switchScrollMode(
ScrollMode.Horizontal
);
},
},
},
});
2021-12-19 12:27:03 +09:00
useEffect(()=>{
if(file_name == 'default.pdf')
setURL('/assets/default/'+file_name);
2021-12-19 12:52:15 +09:00
else setURL('/files/'+file_name);
2021-12-19 12:27:03 +09:00
}, []);
return (
2021-12-31 23:34:51 +09:00
<Worker workerUrl={pdfjsWorker}>
2021-12-21 08:35:53 +09:00
<div
style={{
height: '100vh',
}}
>
{
url &&
2021-12-25 12:17:26 +09:00
<Viewer fileUrl={url}
plugins={[defaultLayoutPluginInstance]}
renderLoader={(percentages) => (
<div style={{ width: '240px' }}>
<ProgressBar progress={Math.round(percentages)} />
</div>
)}
/>
2021-12-21 08:35:53 +09:00
}
</div>
</Worker>
2021-12-19 12:27:03 +09:00
);
}
if(document.getElementById('pdf')){
2021-12-19 12:27:03 +09:00
ReactDOM.render(
<PDFViewer />,
document.getElementById('pdf')
2021-12-19 12:27:03 +09:00
)
}