{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "pdf-viewer-programmatic-annotations",
  "framework": "javascript",
  "type": "registry:component",
  "component": "PdfViewer",
  "variant": "programmatic-annotations",
  "dependencies": [
    "@syncfusion/ej2-pdfviewer",
    "@syncfusion/ej2-dropdowns"
  ],
  "description": "PDF viewer sample selecting annotation types and adding them programmatically.",
  "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/javascript/llms.txt",
    "skillPack": "syncfusion/javascript-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/javascript/pdf-viewer-programmatic-annotations.md"
  },
  "files": [
    {
      "target": "src/components/pdf-viewer-programmatic-annotations/pdf-viewer.html",
      "content": "<div class=\"control-section\">\n    <div class=\"content-wrapper\">\n        <div id=\"annotation-controls\" role=\"group\" aria-label=\"Programmatic annotation controls\"\n            style=\"display:flex; align-items:flex-end; gap:12px; margin-bottom:12px;\">\n            <div style=\"width:220px;\">\n                <label for=\"annotationType\" style=\"display:block; margin-bottom:4px;\">Annotation Type</label>\n                <input id=\"annotationType\" type=\"text\" />\n            </div>\n            <button id=\"addAnnotation\" class=\"e-btn e-primary\" type=\"button\" disabled>Add Annotation</button>\n        </div>\n        <p id=\"annotationStatus\" role=\"status\">Loading PDF document...</p>\n        <div id=\"container\" style=\"height:calc(100vh - 280px); width:100%;\"></div>\n    </div>\n</div>"
    },
    {
      "target": "src/components/pdf-viewer-programmatic-annotations/pdf-viewer.ts",
      "content": "import { DropDownList } from '@syncfusion/ej2-dropdowns';\nimport {\n    Annotation, BookmarkView, CircleSettings, FormDesigner, FormFields,\n    HighlightSettings, InkAnnotationSettings, LinkAnnotation, Magnification, Navigation,\n    PageOrganizer, PdfViewer, Print, RectangleSettings, TextSearch, TextSelection,\n    ThumbnailView, Toolbar, UnderlineSettings\n} from '@syncfusion/ej2-pdfviewer';\nimport type { AnnotationType } from '@syncfusion/ej2-pdfviewer';\n\nPdfViewer.Inject(\n    Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,\n    Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer\n);\n\ntype AnnotationChoice =\n    | 'Highlight' | 'Underline' | 'Strikethrough' | 'Squiggly'\n    | 'Line' | 'Arrow' | 'Rectangle' | 'Circle' | 'Polygon'\n    | 'Distance' | 'Perimeter' | 'Area' | 'Radius' | 'Volume'\n    | 'StickyNotes' | 'Ink' | 'Stamp' | 'CustomStamp' | 'FreeText';\n\nconst annotationTypes = [\n    { text: 'Highlight', value: 'Highlight' },\n    { text: 'Underline', value: 'Underline' },\n    { text: 'Strikethrough', value: 'Strikethrough' },\n    { text: 'Squiggly', value: 'Squiggly' },\n    { text: 'Line', value: 'Line' },\n    { text: 'Arrow', value: 'Arrow' },\n    { text: 'Rectangle', value: 'Rectangle' },\n    { text: 'Circle', value: 'Circle' },\n    { text: 'Polygon', value: 'Polygon' },\n    { text: 'Distance', value: 'Distance' },\n    { text: 'Perimeter', value: 'Perimeter' },\n    { text: 'Area', value: 'Area' },\n    { text: 'Radius', value: 'Radius' },\n    { text: 'Volume', value: 'Volume' },\n    { text: 'Sticky notes', value: 'StickyNotes' },\n    { text: 'Ink', value: 'Ink' },\n    { text: 'Stamp', value: 'Stamp' },\n    { text: 'Custom stamp', value: 'CustomStamp' },\n    { text: 'Free text', value: 'FreeText' }\n];\n\ntype AnnotationSettings = Parameters<Annotation['addAnnotation']>[1];\n\nexport function initPdfViewerProgrammaticAnnotations(): void {\n    const viewer: PdfViewer = new PdfViewer({\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    });\n    const dropDown = new DropDownList({\n        dataSource: annotationTypes,\n        fields: { text: 'text', value: 'value' },\n        value: 'Highlight',\n        width: '100%'\n    });\n    const addButton = document.getElementById('addAnnotation') as HTMLButtonElement;\n    const status = document.getElementById('annotationStatus') as HTMLElement;\n    let annotationCount = 0;\n\n    viewer.documentLoad = () => {\n        addButton.disabled = false;\n        status.textContent = 'Adds the selected annotation to the currently displayed page.';\n    };\n    viewer.appendTo('#container');\n    dropDown.appendTo('#annotationType');\n\n    addButton.addEventListener('click', () => {\n        const annotationType = dropDown.value as AnnotationChoice;\n        const index = annotationCount++ % 16;\n        const offset = { x: 100 + (index % 4) * 115, y: 120 + Math.floor(index / 4) * 75 };\n        const endPoint = { x: offset.x + 120, y: offset.y + 45 };\n        const baseSettings = { offset, pageNumber: viewer.currentPageNumber, author: 'Guest', opacity: 1 };\n        let settings: AnnotationSettings = baseSettings as AnnotationSettings;\n\n        switch (annotationType) {\n            case 'Highlight':\n            case 'Underline':\n            case 'Strikethrough':\n            case 'Squiggly':\n                settings = {\n                    ...baseSettings,\n                    bounds: [{ x: offset.x, y: offset.y, width: 180, height: 16 }],\n                    color: annotationType === 'Highlight' ? '#FFDF56' : '#FF0000'\n                } as unknown as AnnotationSettings;\n                break;\n            case 'Line':\n            case 'Arrow':\n            case 'Distance':\n                settings = {\n                    ...baseSettings,\n                    vertexPoints: [offset, endPoint],\n                    lineHeadEndStyle: annotationType === 'Arrow' ? 'Closed' : 'None'\n                } as AnnotationSettings;\n                break;\n            case 'Rectangle':\n                settings = { ...baseSettings, width: 100, height: 70, strokeColor: '#2563eb' } as RectangleSettings;\n                break;\n            case 'Circle':\n            case 'Radius':\n                settings = { ...baseSettings, width: 80, height: 80, strokeColor: '#2563eb' } as CircleSettings;\n                break;\n            case 'Ink':\n                settings = {\n                    ...baseSettings, width: 100, height: 45, strokeColor: '#2563eb',\n                    path: JSON.stringify([\n                        { command: 'M', x: offset.x, y: offset.y + 35 },\n                        { command: 'L', x: offset.x + 25, y: offset.y + 5 },\n                        { command: 'L', x: offset.x + 50, y: offset.y + 35 },\n                        { command: 'L', x: offset.x + 75, y: offset.y + 5 }\n                    ])\n                } as InkAnnotationSettings;\n                break;\n            case 'FreeText':\n                settings = {\n                    ...baseSettings, width: 190, height: 32, fontSize: 14,\n                    fontColor: '#1f2937', defaultText: 'Added programmatically'\n                } as AnnotationSettings;\n                break;\n            default:\n                settings = { ...baseSettings, width: 100, height: 60 } as AnnotationSettings;\n        }\n\n        viewer.annotation.addAnnotation(annotationType as AnnotationType, settings);\n    });\n}\n"
    }
  ]
}