App.jsx
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 |
import React, { useState } from 'react'; const SimplePDFViewer = () => { const [fileURL, setFileURL] = useState(null); const handleFileChange = (event) => { const file = event.target.files[0]; if (!file || file.type !== 'application/pdf') { alert('Please select a valid PDF file'); return; } const fileReader = new FileReader(); fileReader.onload = (e) => { setFileURL(e.target.result); }; fileReader.readAsDataURL(file); }; return ( <div style={{ padding: '1rem' }}> <h2>Basic PDF Viewer (No external libraries)</h2> <input type="file" accept="application/pdf" onChange={handleFileChange} /> {fileURL ? ( <iframe title="PDF Preview" src={fileURL} width="100%" height="600px" style={{ border: '1px solid #ccc', marginTop: '1rem' }} /> ) : ( <p style={{ marginTop: '1rem' }}>Please upload a PDF to view</p> )} </div> ); }; export default SimplePDFViewer; |