{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "pdf-viewer-semantic-text-comparison",
  "framework": "react",
  "type": "registry:component",
  "component": "PdfViewer",
  "variant": "semantic-text-comparison",
  "dependencies": [
    "@syncfusion/ej2-react-pdfviewer"
  ],
  "description": "Compare two selected PDF files with semantic text comparison, synchronized scrolling, highlighted changes, and a difference panel.",
  "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-semantic-text-comparison.md"
  },
  "files": [
    {
      "target": "src/components/pdf-viewer-semantic-text-comparison/PdfViewer.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport {\n    PdfComparerComponent, TextComparisonOptions,\n    type PdfComparerComponent as PdfComparerComponentType\n} from '@syncfusion/ej2-react-pdfviewer';\n\ntype ComparisonDocuments = {\n    original: string;\n    modified: string;\n    id: number;\n};\n\nconst resourceUrl = 'https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib';\nconst comparisonOptions = {\n    beforeColor: '#FF0000',\n    afterColor: '#00FF00',\n    beforeColorOpacity: 0.4,\n    afterColorOpacity: 0.4,\n    enableHighlights: true\n} as TextComparisonOptions;\n\nfunction SemanticTextComparison() {\n    const comparerRef = useRef<PdfComparerComponentType | null>(null);\n    const originalInputRef = useRef<HTMLInputElement | null>(null);\n    const modifiedInputRef = useRef<HTMLInputElement | null>(null);\n    const comparisonId = useRef(0);\n    const [originalFile, setOriginalFile] = useState<File | null>(null);\n    const [modifiedFile, setModifiedFile] = useState<File | null>(null);\n    const [comparisonDocuments, setComparisonDocuments] = useState<ComparisonDocuments | null>(null);\n    const [isComparing, setIsComparing] = useState(false);\n    const [statusMessage, setStatusMessage] = useState('Choose two PDF files to compare.');\n\n    useEffect(() => {\n        const comparer = comparerRef.current;\n        if (!comparisonDocuments || !comparer) {\n            return;\n        }\n\n        let isCurrentComparison = true;\n        const runComparison = async () => {\n            try {\n                await comparer.compare();\n                if (isCurrentComparison) {\n                    setStatusMessage('Comparison requested. Review the highlighted changes in both viewers and the difference panel.');\n                }\n            } catch (error) {\n                console.error('Unable to compare the selected PDF documents.', error);\n                if (isCurrentComparison) {\n                    setStatusMessage('Unable to compare the selected PDFs. See the browser console for details.');\n                }\n            } finally {\n                if (isCurrentComparison) {\n                    setIsComparing(false);\n                }\n            }\n        };\n\n        void runComparison();\n        return () => {\n            isCurrentComparison = false;\n            URL.revokeObjectURL(comparisonDocuments.original);\n            URL.revokeObjectURL(comparisonDocuments.modified);\n        };\n    }, [comparisonDocuments]);\n\n    const selectFile = (\n        file: File | undefined,\n        setSelectedFile: (value: File | null) => void,\n        inputRef: React.RefObject<HTMLInputElement | null>\n    ) => {\n        if (!file) {\n            return;\n        }\n        if (!file.name.toLowerCase().endsWith('.pdf')) {\n            setStatusMessage('Select a file with the .pdf extension.');\n            if (inputRef.current) {\n                inputRef.current.value = '';\n            }\n            return;\n        }\n\n        setSelectedFile(file);\n        setComparisonDocuments(null);\n        setIsComparing(false);\n        setStatusMessage('PDF selected. Choose the other document or compare the selected files.');\n    };\n\n    const clearFile = (\n        setSelectedFile: (value: File | null) => void,\n        inputRef: React.RefObject<HTMLInputElement | null>\n    ) => {\n        setSelectedFile(null);\n        setComparisonDocuments(null);\n        setIsComparing(false);\n        if (inputRef.current) {\n            inputRef.current.value = '';\n        }\n        setStatusMessage('Choose two PDF files to compare.');\n    };\n\n    const compareDocuments = () => {\n        if (!originalFile || !modifiedFile) {\n            return;\n        }\n\n        setIsComparing(true);\n        setStatusMessage('Loading PDF documents for comparison...');\n        let originalUrl: string | null = null;\n        try {\n            originalUrl = URL.createObjectURL(originalFile);\n            const modifiedUrl = URL.createObjectURL(modifiedFile);\n            setComparisonDocuments({\n                original: originalUrl,\n                modified: modifiedUrl,\n                id: ++comparisonId.current\n            });\n        } catch (error) {\n            if (originalUrl) {\n                URL.revokeObjectURL(originalUrl);\n            }\n            console.error('Unable to prepare the selected PDF files for comparison.', error);\n            setIsComparing(false);\n            setStatusMessage('Unable to prepare the selected PDFs. Please try selecting them again.');\n        }\n    };\n\n    return (\n        <div className='control-section'>\n            <div\n                role='group'\n                aria-label='PDF comparison files'\n                style={{\n                    display: 'flex',\n                    alignItems: 'flex-end',\n                    flexWrap: 'wrap',\n                    gap: '12px',\n                    marginBottom: '12px'\n                }}\n            >\n                <div style={{ minWidth: '260px', flex: '1 1 260px' }}>\n                    <label htmlFor='original-pdf-file' style={{ display: 'block', marginBottom: '4px' }}>\n                        Original document\n                    </label>\n                    <input\n                        id='original-pdf-file'\n                        ref={originalInputRef}\n                        className='e-input'\n                        type='file'\n                        accept='.pdf,application/pdf'\n                        onChange={(event) => selectFile(\n                            event.currentTarget.files?.[0],\n                            setOriginalFile,\n                            originalInputRef\n                        )}\n                    />\n                    <div style={{ display: 'flex', alignItems: 'center', gap: '8px', marginTop: '4px' }}>\n                        <span>{originalFile?.name ?? 'Choose a PDF file'}</span>\n                        {originalFile && (\n                            <button\n                                className='e-btn'\n                                type='button'\n                                onClick={() => clearFile(setOriginalFile, originalInputRef)}\n                            >\n                                Remove\n                            </button>\n                        )}\n                    </div>\n                </div>\n                <div style={{ minWidth: '260px', flex: '1 1 260px' }}>\n                    <label htmlFor='modified-pdf-file' style={{ display: 'block', marginBottom: '4px' }}>\n                        Modified document\n                    </label>\n                    <input\n                        id='modified-pdf-file'\n                        ref={modifiedInputRef}\n                        className='e-input'\n                        type='file'\n                        accept='.pdf,application/pdf'\n                        onChange={(event) => selectFile(\n                            event.currentTarget.files?.[0],\n                            setModifiedFile,\n                            modifiedInputRef\n                        )}\n                    />\n                    <div style={{ display: 'flex', alignItems: 'center', gap: '8px', marginTop: '4px' }}>\n                        <span>{modifiedFile?.name ?? 'Choose a PDF file'}</span>\n                        {modifiedFile && (\n                            <button\n                                className='e-btn'\n                                type='button'\n                                onClick={() => clearFile(setModifiedFile, modifiedInputRef)}\n                            >\n                                Remove\n                            </button>\n                        )}\n                    </div>\n                </div>\n                <button\n                    className='e-btn e-primary'\n                    type='button'\n                    onClick={compareDocuments}\n                    disabled={!originalFile || !modifiedFile || isComparing}\n                >\n                    {isComparing ? 'Comparing...' : 'Compare'}\n                </button>\n            </div>\n            <p role='status' aria-live='polite'>{statusMessage}</p>\n            {comparisonDocuments && (\n                <div style={{ height: '640px', width: '100%' }}>\n                    <PdfComparerComponent\n                        key={comparisonDocuments.id}\n                        ref={comparerRef}\n                        resourceUrl={resourceUrl}\n                        comparisonOptions={comparisonOptions}\n                        originalDocumentPath={comparisonDocuments.original}\n                        modifiedDocumentPath={comparisonDocuments.modified}\n                        enableDifferencePanel={true}\n                        enableSyncScrolling={true}\n                        height='640px'\n                        width='100%'\n                    />\n                </div>\n            )}\n        </div>\n    );\n}\n\nexport default SemanticTextComparison;\n"
    }
  ]
}