mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 05:59:34 +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';
|
import { EmbedPDF } from '@simplepdf/react-embed-pdf';
|
||||||
|
|
||||||
export default function PdfEditor({ title }: ToolComponentProps) {
|
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 (
|
return (
|
||||||
<ToolContent
|
<ToolContent
|
||||||
title={title}
|
title={title}
|
||||||
initialValues={{}}
|
initialValues={{}}
|
||||||
getGroups={null}
|
getGroups={null}
|
||||||
input={input}
|
input={null}
|
||||||
inputComponent={
|
inputComponent={
|
||||||
<>
|
<Box sx={{ width: '100%', height: '80vh' }}>
|
||||||
{pdfUrl ? (
|
<EmbedPDF mode="inline" style={{ width: '100%', height: '100%' }} />
|
||||||
<Box sx={{ width: '100%', height: '80vh' }}>
|
</Box>
|
||||||
<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"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
toolInfo={{
|
toolInfo={{
|
||||||
title: 'PDF Editor',
|
title: 'PDF Editor',
|
||||||
|
Reference in New Issue
Block a user