0.Public -> create Folder pdf -> Drop 2 files pdf
Plan:
When we want to read file 1 or file 2, we input 1st or 2nd file
-> then it will be the reference for onClick
and src link when we click on will also be another reference
1. App.jsx
import React, {useRef,useState} from 'react'
const Ex08 = () => {
const inputRef = useRef();
const pdfRef = useRef();
const switchFile = (num) =>{
console.log('pdf',pdfRef.current.src);
pdfRef.current.src = `./pdf/pdfFile${num}.pdf`
}
const changePdf = (src)=>{
console.log('inputRef',inputRef.current.value);
if(inputRef.current.value === '첫번째'){
switchFile(1)
}else if(inputRef.current.value === '두번째'){
switchFile(2)
}
};
return (
<div>
<input type="text" ref ={inputRef} />
<button onClick={changePdf} >pdf 변경</button>
<iframe
src = {switchFile}
width= "100%"
height="90%"
ref = {pdfRef}
>
</iframe>
</div>
)
}
export default App
Nowadays PDF files are quite popular and are used for sending documents. But unfortunately it is not always convenient to work with these documents. If you want to quickly edit these documents and send them, check out https://www.pdfplatform.com/. I have been using this service for a long time and with its help working with PDF files is very fast and convenient