index.tsx
749 Bytes
import { useEffect, useState } from 'react';
import './index.less';
interface pdfPreviewProps {
url?: string
}
const pdfPreview = (props: pdfPreviewProps) => {
const [filePath, setFilePath] = useState<string>();
const _origin = window.location.origin?.includes('localhost') ? 'https://lt-test.qgutech.com' : window.location.origin;
useEffect(()=>{
if (props.url) {
const _url = encodeURIComponent(props.url);
setFilePath(_url);
}
},[props.url])
return (
<div className={'pdfPreview'}>
<iframe
title="pdf-preview"
style={{ width: '100%', height: '100%' }}
src={`${_origin}/pdf/web/viewer.html?file=${filePath}`}
/>
</div>
);
};
export default pdfPreview;