mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-18 21:49:31 +02:00
refactor: PDF editor
This commit is contained in:
@@ -6,45 +6,16 @@ import { ToolComponentProps } from '@tools/defineTool';
|
||||
import { EmbedPDF } from '@simplepdf/react-embed-pdf';
|
||||
|
||||
export default function PdfEditor({ title }: ToolComponentProps) {
|
||||
const [input, setInput] = useState<File | null>(null);
|
||||
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
|
||||
|
||||
const onFileChange = (file: File | null) => {
|
||||
if (file) {
|
||||
setInput(file);
|
||||
const url = URL.createObjectURL(file);
|
||||
setPdfUrl(url);
|
||||
} else {
|
||||
setInput(null);
|
||||
setPdfUrl(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ToolContent
|
||||
title={title}
|
||||
initialValues={{}}
|
||||
getGroups={null}
|
||||
input={input}
|
||||
input={null}
|
||||
inputComponent={
|
||||
<>
|
||||
{pdfUrl ? (
|
||||
<Box sx={{ width: '100%', height: '80vh' }}>
|
||||
<EmbedPDF
|
||||
mode="inline"
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
documentURL={pdfUrl}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<ToolPdfInput
|
||||
value={input}
|
||||
onChange={onFileChange}
|
||||
accept={['application/pdf']}
|
||||
title="Upload a PDF to edit"
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
<Box sx={{ width: '100%', height: '80vh' }}>
|
||||
<EmbedPDF mode="inline" style={{ width: '100%', height: '100%' }} />
|
||||
</Box>
|
||||
}
|
||||
toolInfo={{
|
||||
title: 'PDF Editor',
|
||||
|
Reference in New Issue
Block a user