chore: pdf editor using embedpdf

This commit is contained in:
Chesterkxng committed 2026-10-20 23:23:06 +00:00
1 parent 55a864d36f
commit c6657cc673
2 files changed
+58 -25

No files matched your search

+3 -1
View File
@@ -41,7 +41,9 @@
"editor": {
"description": "Advanced PDF editor with annotation, form-fill, highlight, and export capabilities. Edit your PDFs directly in the browser with professional-grade tools including text insertion, drawing, highlighting, signing and form filling.",
"shortDescription": "Edit PDFs with advanced annotation, signing and editing tools",
"title": "PDF Editor"
"title": "PDF Editor",
"upload": "Upload PDF",
"clear": "Clear Input"
},
"formBuilder": {
"title": "PDF Form Builder",
+55 -24
View File
@@ -1,29 +1,60 @@
import React from 'react';
import { Box } from '@mui/material';
import ToolContent from '@components/ToolContent';
import { ToolComponentProps } from '@tools/defineTool';
import { EmbedPDF } from '@simplepdf/react-embed-pdf';
import { useState, useEffect, useRef } from 'react';
import { Box, Button } from '@mui/material';
import { PDFViewer } from '@embedpdf/react-pdf-viewer';
import { useTranslation } from 'react-i18next';
export default function PdfEditor() {
const { t } = useTranslation('pdf');
const [src, setSrc] = useState<string | null>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) setSrc(URL.createObjectURL(file));
};
const handleClear = () => {
setSrc(null);
if (fileInputRef.current) fileInputRef.current.value = '';
};
useEffect(
() => () => {
if (src) URL.revokeObjectURL(src);
},
[src]
);
export default function PdfEditor({ title }: ToolComponentProps) {
return (
<ToolContent
title={title}
initialValues={{}}
getGroups={null}
input={null}
inputComponent={
<Box sx={{ width: '100%', height: '80vh' }}>
<EmbedPDF mode="inline" style={{ width: '100%', height: '100%' }} />
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
<Box sx={{ p: 1 }}>
<Button variant="contained" component="label">
{t('editor.upload')}
<input
type="file"
accept="application/pdf"
hidden
onChange={handleUpload}
/>
</Button>
<Button
variant="outlined"
style={{ marginLeft: '10px' }}
disabled={!src}
onClick={handleClear}
>
{t('editor.clear')}
</Button>
</Box>
{src && (
<Box sx={{ flex: 1, minHeight: 0, overflow: 'hidden' }}>
<PDFViewer
key={src}
config={{ src, theme: { preference: 'system' } }}
style={{ height: '100%' }}
/>
</Box>
}
toolInfo={{
title: 'PDF Editor',
description:
'Edit, annotate, highlight, fill forms, and export your PDFs entirely in the browser. Add text, drawings, signatures, and more to your PDF documents with this powerful online editor.'
}}
compute={() => {
/* no background compute required */
}}
/>
)}
</Box>
);
}