{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "pdf-viewer-programmatic-annotations",
  "framework": "angular",
  "type": "registry:component",
  "component": "PdfViewer",
  "variant": "programmatic-annotations",
  "dependencies": [
    "@syncfusion/ej2-angular-pdfviewer",
    "@syncfusion/ej2-angular-dropdowns"
  ],
  "description": "Programmatically add text, shape, measurement, stamp, and ink annotations to the current PDF page.",
  "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/angular/llms.txt",
    "skillPack": "syncfusion/angular-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/angular/pdf-viewer-programmatic-annotations.md"
  },
  "files": [
    {
      "target": "src/components/pdf-viewer-programmatic-annotations/pdf-viewer.component.html",
      "content": "<div class=\"control-section\">\n    <div role=\"group\" aria-label=\"Programmatic annotation controls\"\n        style=\"display:flex;align-items:flex-end;flex-wrap:wrap;gap:12px;margin-bottom:12px\">\n        <div style=\"width:220px\">\n            <label for=\"annotation-type\" style=\"display:block;margin-bottom:4px\">Annotation Type</label>\n            <ejs-dropdownlist id=\"annotation-type\" [dataSource]=\"annotationTypes\" [fields]=\"annotationTypeFields\"\n                [value]=\"annotationType\" placeholder=\"Select annotation type\" [enabled]=\"isDocumentLoaded\"\n                (change)=\"onAnnotationTypeChange($event)\">\n            </ejs-dropdownlist>\n        </div>\n        <button class=\"e-btn e-primary\" type=\"button\" (click)=\"addSelectedAnnotation()\"\n            [disabled]=\"!isDocumentLoaded\">\n            Add Annotation\n        </button>\n    </div>\n    <p role=\"status\">\n        {{ isDocumentLoaded ? 'Adds the selected annotation to the currently displayed page.' : 'Loading PDF document...' }}\n    </p>\n    <ejs-pdfviewer #pdfviewer id=\"programmatic-annotations-viewer\" [documentPath]=\"document\"\n        [resourceUrl]=\"resource\" (documentLoad)=\"onDocumentLoad()\" style=\"height:640px;display:block\">\n    </ejs-pdfviewer>\n</div>\n"
    },
    {
      "target": "src/components/pdf-viewer-programmatic-annotations/pdf-viewer.component.ts",
      "content": "import { Component, ViewChild } from '@angular/core';\nimport {\n    AnnotationService,\n    BookmarkViewService,\n    DynamicStampItem,\n    FormDesignerService,\n    FormFieldsService,\n    LinkAnnotationService,\n    MagnificationService,\n    NavigationService,\n    PageOrganizerService,\n    PdfViewerComponent,\n    PdfViewerModule,\n    PrintService,\n    TextSearchService,\n    TextSelectionService,\n    ThumbnailViewService,\n    ToolbarService\n} from '@syncfusion/ej2-angular-pdfviewer';\nimport { ChangeEventArgs, DropDownListModule } from '@syncfusion/ej2-angular-dropdowns';\n\ntype AnnotationType =\n    | 'Highlight' | 'Underline' | 'Strikethrough' | 'Squiggly'\n    | 'Line' | 'Arrow' | 'Rectangle' | 'Circle' | 'Polygon'\n    | 'Distance' | 'Perimeter' | 'Area' | 'Radius' | 'Volume'\n    | 'StickyNotes' | 'Ink' | 'Stamp' | 'CustomStamp' | 'FreeText';\ntype AnnotationSettings = NonNullable<Parameters<PdfViewerComponent['annotation']['addAnnotation']>[1]>;\n\n@Component({\n    selector: 'control-content',\n    templateUrl: 'pdf-viewer.component.html',\n    providers: [\n        LinkAnnotationService, BookmarkViewService, MagnificationService, ThumbnailViewService,\n        ToolbarService, NavigationService, TextSearchService, TextSelectionService, PrintService,\n        AnnotationService, FormFieldsService, FormDesignerService, PageOrganizerService\n    ],\n    standalone: true,\n    imports: [PdfViewerModule, DropDownListModule]\n})\nexport class ProgrammaticAnnotationsComponent {\n    @ViewChild('pdfviewer')\n    public pdfviewerControl!: PdfViewerComponent;\n\n    public readonly resource = 'https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib';\n    public readonly document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';\n    public readonly annotationTypes: { value: AnnotationType; label: string }[] = [\n        { value: 'Highlight', label: 'Highlight' },\n        { value: 'Underline', label: 'Underline' },\n        { value: 'Strikethrough', label: 'Strikethrough' },\n        { value: 'Squiggly', label: 'Squiggly' },\n        { value: 'Line', label: 'Line' },\n        { value: 'Arrow', label: 'Arrow' },\n        { value: 'Rectangle', label: 'Rectangle' },\n        { value: 'Circle', label: 'Circle' },\n        { value: 'Polygon', label: 'Polygon' },\n        { value: 'Distance', label: 'Distance' },\n        { value: 'Perimeter', label: 'Perimeter' },\n        { value: 'Area', label: 'Area' },\n        { value: 'Radius', label: 'Radius' },\n        { value: 'Volume', label: 'Volume' },\n        { value: 'StickyNotes', label: 'Sticky Notes' },\n        { value: 'Ink', label: 'Ink' },\n        { value: 'Stamp', label: 'Stamp' },\n        { value: 'CustomStamp', label: 'Custom Stamp' },\n        { value: 'FreeText', label: 'Free Text' }\n    ];\n    public readonly annotationTypeFields = { text: 'label', value: 'value' };\n    public annotationType: AnnotationType = 'Highlight';\n    public isDocumentLoaded = false;\n    private annotationCount = 0;\n    private readonly customStampSvg = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"180\" height=\"60\" viewBox=\"0 0 180 60\"><rect x=\"2\" y=\"2\" width=\"176\" height=\"56\" rx=\"4\" fill=\"white\" stroke=\"#2563eb\" stroke-width=\"4\"/><text x=\"90\" y=\"38\" text-anchor=\"middle\" font-family=\"Arial\" font-size=\"21\" font-weight=\"bold\" fill=\"#2563eb\">REVIEWED</text></svg>';\n\n    public onDocumentLoad(): void {\n        this.isDocumentLoaded = true;\n    }\n\n    public onAnnotationTypeChange(event: ChangeEventArgs): void {\n        if (typeof event.value === 'string') {\n            this.annotationType = event.value as AnnotationType;\n        }\n    }\n\n    public addSelectedAnnotation(): void {\n        if (!this.isDocumentLoaded) {\n            return;\n        }\n\n        const index = this.annotationCount++ % 16;\n        const offset = { x: 100 + (index % 4) * 115, y: 120 + Math.floor(index / 4) * 75 };\n        const pageNumber = this.pdfviewerControl.currentPageNumber;\n        const baseSettings = { offset, pageNumber, author: 'Guest', opacity: 1 };\n        const endPoint = { x: offset.x + 120, y: offset.y + 45 };\n        let settings: object = baseSettings;\n\n        switch (this.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: this.annotationType === 'Highlight' ? '#FFDF56' : '#FF0000'\n                };\n                break;\n            case 'Line':\n            case 'Arrow':\n            case 'Distance':\n                settings = {\n                    ...baseSettings,\n                    vertexPoints: [offset, endPoint],\n                    lineHeadEndStyle: this.annotationType === 'Arrow' ? 'Closed' : 'None'\n                };\n                break;\n            case 'Rectangle':\n                settings = { ...baseSettings, width: 100, height: 70, strokeColor: '#2563eb' };\n                break;\n            case 'Circle':\n            case 'Radius':\n                settings = { ...baseSettings, width: 80, height: 80, strokeColor: '#2563eb' };\n                break;\n            case 'Polygon':\n                settings = {\n                    ...baseSettings,\n                    vertexPoints: [\n                        offset,\n                        { x: offset.x + 45, y: offset.y - 20 },\n                        { x: offset.x + 90, y: offset.y + 10 },\n                        { x: offset.x + 75, y: offset.y + 60 },\n                        { x: offset.x + 15, y: offset.y + 60 },\n                        offset\n                    ],\n                    width: 90,\n                    height: 80,\n                    strokeColor: '#2563eb'\n                };\n                break;\n            case 'Perimeter':\n                settings = {\n                    ...baseSettings,\n                    vertexPoints: [offset, { x: offset.x + 75, y: offset.y }, { x: offset.x + 80, y: offset.y + 55 }],\n                    strokeColor: '#2563eb'\n                };\n                break;\n            case 'Area':\n                settings = {\n                    ...baseSettings,\n                    vertexPoints: [\n                        offset,\n                        { x: offset.x + 90, y: offset.y },\n                        { x: offset.x + 45, y: offset.y + 55 },\n                        offset\n                    ],\n                    width: 90,\n                    height: 55,\n                    fillColor: '#dbeafe',\n                    strokeColor: '#2563eb'\n                };\n                break;\n            case 'Volume':\n                settings = {\n                    ...baseSettings,\n                    vertexPoints: [\n                        offset,\n                        { x: offset.x, y: offset.y + 55 },\n                        { x: offset.x + 75, y: offset.y + 55 },\n                        { x: offset.x + 75, y: offset.y },\n                        offset,\n                        { x: offset.x + 25, y: offset.y - 20 },\n                        { x: offset.x + 100, y: offset.y - 20 },\n                        { x: offset.x + 100, y: offset.y + 35 },\n                        { x: offset.x + 75, y: offset.y + 55 }\n                    ],\n                    width: 100,\n                    height: 75,\n                    strokeColor: '#2563eb'\n                };\n                break;\n            case 'StickyNotes':\n                settings = { ...baseSettings, subject: 'Programmatic review note' };\n                break;\n            case 'Ink':\n                settings = {\n                    ...baseSettings,\n                    width: 100,\n                    height: 45,\n                    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                };\n                break;\n            case 'Stamp':\n                this.pdfviewerControl.annotation.addAnnotation(\n                    'Stamp',\n                    { ...baseSettings, width: 140, height: 55 } as AnnotationSettings,\n                    DynamicStampItem.Approved\n                );\n                return;\n            case 'CustomStamp':\n                this.pdfviewerControl.annotation.addAnnotation('Stamp', {\n                    ...baseSettings,\n                    width: 150,\n                    height: 50,\n                    customStamps: [{\n                        customStampName: 'Reviewed',\n                        customStampImageSource: `data:image/svg+xml,${encodeURIComponent(this.customStampSvg)}`\n                    }]\n                } as AnnotationSettings);\n                return;\n            case 'FreeText':\n                settings = {\n                    ...baseSettings,\n                    width: 190,\n                    height: 32,\n                    fontSize: 14,\n                    fontColor: '#1f2937',\n                    defaultText: 'Added programmatically'\n                };\n                break;\n        }\n\n        this.pdfviewerControl.annotation.addAnnotation(\n            this.annotationType as Parameters<PdfViewerComponent['annotation']['addAnnotation']>[0],\n            settings as AnnotationSettings\n        );\n    }\n}\n"
    }
  ]
}