-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathApp.tsx
More file actions
76 lines (64 loc) · 2.58 KB
/
App.tsx
File metadata and controls
76 lines (64 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, {useState} from 'react';
import pdfWorkerSource from 'pdfjs-dist/build/pdf.worker.min.mjs';
import * as pdfjs from 'pdfjs-dist';
import ReactFastPDF, {PDFPreviewer} from 'react-fast-pdf';
import './index.css';
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'}));
function App() {
const [file, setFile] = useState<string | null>(null);
// `.default` is required when referencing the legacy CJS package.
const packageName = ('default' in ReactFastPDF ? (ReactFastPDF.default as {PackageName: string}) : ReactFastPDF).PackageName;
return (
<main className="container">
<h1 className="title">Hello, I am {packageName}!</h1>
{file ? (
<>
<button
className="button button_back"
type="button"
onClick={() => setFile(null)}
>
Back
</button>
<PDFPreviewer
file={file}
pageMaxWidth={1000}
isSmallScreen={false}
/>
</>
) : (
<>
<h3>Please choose a file for previewing:</h3>
<div className="buttons_container">
<button
className="button"
type="button"
onClick={() => setFile('example.pdf')}
>
example.pdf
</button>
<button
className="button"
type="button"
onClick={() => setFile('example_protected.pdf')}
>
example_protected.pdf (Password: 123456)
</button>
<input
className="button"
type="file"
onChange={(event) => {
const uploadedFile = event?.target?.files?.[0];
if (!uploadedFile) {
return;
}
setFile(URL.createObjectURL(uploadedFile));
}}
/>
</div>
</>
)}
</main>
);
}
export default App;