实际上,我想防止用户下载PDF文件。 尝试通过添加事件侦听器禁用它。
useEffect(() => {
let element = document.getElementById('pdf-div')
if(element)
element.addEventListener("contextmenu", (event: any) => event.preventDefault());
}, [])
return (
<>
{
file.includes('.png') ?
<img src={require(`./../../mocks/${file}`)} alt="" className='pdf-document-img' /> :
<object id={'pdf-div'} ref={ref} className='pdf-document' data={`${file}#toolbar=0`} type="application/pdf">
<embed id={'pdf-div'} ref={ref} src={file} type="application/pdf" />
</object>
}
</>
);