{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "pdf-viewer-redaction",
  "framework": "react",
  "type": "registry:component",
  "component": "PdfViewer",
  "variant": "redaction",
  "dependencies": [
    "@syncfusion/ej2-react-pdfviewer"
  ],
  "description": "PDF viewer supports redaction annotations added programmatically or by searching for text, with one confirmed action to apply them permanently.",
  "meta": {
    "essentialStudioRelease": "2026 Volume 3 (v35.1.37)",
    "license": "commercial-or-community",
    "licenseNote": "The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md",
    "requiresLicenseKey": true,
    "requiresServerEndpoint": false,
    "platformIndex": "https://ai.syncfusion.com/react/llms.txt",
    "skillPack": "syncfusion/react-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/react/ts/pdf-viewer-redaction.md"
  },
  "files": [
    {
      "target": "src/components/pdf-viewer-redaction/PdfViewer.tsx",
      "content": "import { useRef, useState } from 'react';\nimport {\n    Annotation, BookmarkView, FormDesigner, FormFields, Inject, LinkAnnotation, Magnification,\n    Navigation, PageOrganizer, PdfViewerComponent, Print, RedactionSettings, TextSearch,\n    TextSelection, ThumbnailView, Toolbar\n} from '@syncfusion/ej2-react-pdfviewer';\n\nfunction RedactionSample() {\n    const viewerRef = useRef<PdfViewerComponent | null>(null);\n    const isApplyingRedactions = useRef(false);\n    const [isDocumentLoaded, setIsDocumentLoaded] = useState(false);\n    const [searchText, setSearchText] = useState('');\n    const [isSearching, setIsSearching] = useState(false);\n    const [statusMessage, setStatusMessage] = useState('Loading PDF document...');\n\n    const onDocumentLoad = () => {\n        viewerRef.current?.toolbar.showRedactionToolbar(true);\n        setIsDocumentLoaded(true);\n        if (isApplyingRedactions.current) {\n            isApplyingRedactions.current = false;\n            setStatusMessage('Redactions applied to the document.');\n        } else {\n            setStatusMessage('Document loaded. Add a redaction or search for text to mark.');\n        }\n    };\n\n    const addRedaction = () => {\n        const viewer = viewerRef.current;\n        if (!viewer) {\n            return;\n        }\n\n        viewer.annotation.addAnnotation('Redaction', {\n            bound: { x: 150, y: 400, width: 200, height: 40 },\n            pageNumber: viewer.currentPageNumber,\n            overlayText: 'Confidential',\n            fillColor: '#000000',\n            fontColor: '#FFFFFF'\n        } as RedactionSettings);\n        setStatusMessage('Redaction added to the current page. Apply Redactions to make it permanent.');\n    };\n\n    const searchAndMarkRedactions = async () => {\n        const viewer = viewerRef.current;\n        const term = searchText.trim();\n        if (!viewer) {\n            return;\n        }\n        if (!term) {\n            setStatusMessage('Enter text to search for and redact.');\n            return;\n        }\n\n        setIsSearching(true);\n        setStatusMessage(`Searching for \"${term}\"...`);\n\n        try {\n            const results = await viewer.textSearchModule.findTextAsync(term, false);\n            let redactionCount = 0;\n\n            for (const result of results) {\n                if (typeof result.pageIndex !== 'number' || !result.bounds?.length) {\n                    continue;\n                }\n\n                for (const bound of result.bounds) {\n                    viewer.annotation.addAnnotation('Redaction', {\n                        bound: {\n                            x: bound.x * (96 / 72),\n                            y: bound.y * (96 / 72),\n                            width: bound.width * (96 / 72),\n                            height: bound.height * (96 / 72)\n                        },\n                        pageNumber: result.pageIndex + 1,\n                        overlayText: 'Confidential',\n                        fillColor: '#000000',\n                        fontColor: '#FFFFFF'\n                    } as RedactionSettings);\n                    redactionCount++;\n                }\n            }\n\n            setStatusMessage(redactionCount\n                ? `Marked ${redactionCount} match${redactionCount === 1 ? '' : 'es'} for \"${term}\". Apply Redactions to make them permanent.`\n                : `No matches found for \"${term}\".`);\n        } catch (error) {\n            console.error('Unable to search the PDF for redaction text.', error);\n            setStatusMessage('Unable to search the PDF. See the browser console for details.');\n        } finally {\n            setIsSearching(false);\n        }\n    };\n\n    const applyRedactions = () => {\n        const viewer = viewerRef.current;\n        if (!viewer) {\n            return;\n        }\n        if (!window.confirm('Applying redactions permanently removes the marked content. Continue?')) {\n            setStatusMessage('Redaction application canceled.');\n            return;\n        }\n\n        isApplyingRedactions.current = true;\n        viewer.annotation.redact();\n        setStatusMessage('Applying redactions. The viewer will reload when processing is complete.');\n    };\n\n    return (\n        <div className='control-section'>\n            <div\n                role='group'\n                aria-label='Redaction controls'\n                style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'flex-end', gap: '12px', marginBottom: '12px' }}\n            >\n                <button\n                    className='e-btn e-primary'\n                    type='button'\n                    onClick={addRedaction}\n                    disabled={!isDocumentLoaded}\n                >\n                    Add Redaction\n                </button>\n                <div style={{ width: '220px' }}>\n                    <label htmlFor='redaction-search-text' style={{ display: 'block', marginBottom: '4px' }}>\n                        Text to redact\n                    </label>\n                    <input\n                        id='redaction-search-text'\n                        className='e-input'\n                        type='search'\n                        value={searchText}\n                        onChange={(event) => setSearchText(event.target.value)}\n                        disabled={!isDocumentLoaded || isSearching}\n                    />\n                </div>\n                <button\n                    className='e-btn'\n                    type='button'\n                    onClick={searchAndMarkRedactions}\n                    disabled={!isDocumentLoaded || isSearching}\n                >\n                    {isSearching ? 'Searching...' : 'Search & Mark for Redaction'}\n                </button>\n                <button\n                    className='e-btn e-danger'\n                    type='button'\n                    onClick={applyRedactions}\n                    disabled={!isDocumentLoaded}\n                >\n                    Apply Redactions\n                </button>\n            </div>\n            <p role='status'>{statusMessage}</p>\n            <PdfViewerComponent\n                id='redaction-viewer'\n                ref={viewerRef}\n                documentPath='https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf'\n                resourceUrl='https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib'\n                isExtractText={true}\n                toolbarSettings={{\n                    showTooltip: true,\n                    toolbarItems: [\n                        'OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool',\n                        'PanTool', 'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool',\n                        'RedactionEditTool', 'FormDesignerEditTool', 'SearchOption', 'PrintOption',\n                        'DownloadOption'\n                    ]\n                }}\n                documentLoad={onDocumentLoad}\n                style={{ height: '640px' }}\n            >\n                <Inject services={[\n                    Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,\n                    Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer\n                ]} />\n            </PdfViewerComponent>\n        </div>\n    );\n}\n\nexport default RedactionSample;\n"
    }
  ]
}