|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Add Area Measurement Annotations in Angular PDF Viewer | Syncfusion |
| 4 | +description: Learn how to enable, draw, customize, and manage Area measurement annotations in the Syncfusion Angular PDF Viewer. |
| 5 | +platform: document-processing |
| 6 | +control: PDF Viewer |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Add Area Measurement Annotations in Angular PDF Viewer |
| 12 | +Area is a measurement annotation used to calculate the surface of a closed region on a PDF page—ideal for engineering, construction, or design reviews. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Enable Area Measurement |
| 17 | + |
| 18 | +To enable Area annotations, inject the following modules into the Angular PDF Viewer: |
| 19 | + |
| 20 | +- [**Annotation**](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#annotation) |
| 21 | +- [**Toolbar**](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#toolbar) |
| 22 | + |
| 23 | +{% tabs %} |
| 24 | +{% highlight ts tabtitle="Standalone" %} |
| 25 | + |
| 26 | +import { Component } from '@angular/core'; |
| 27 | +import { |
| 28 | + PdfViewerModule, |
| 29 | + ToolbarService, |
| 30 | + AnnotationService |
| 31 | +} from '@syncfusion/ej2-angular-pdfviewer'; |
| 32 | + |
| 33 | +@Component({ |
| 34 | + selector: 'app-root', |
| 35 | + template: ` |
| 36 | + <div class="content-wrapper"> |
| 37 | + <ejs-pdfviewer |
| 38 | + id="pdfViewer" |
| 39 | + [documentPath]="document" |
| 40 | + [resourceUrl]="resource" |
| 41 | + style="height:650px;display:block"> |
| 42 | + </ejs-pdfviewer> |
| 43 | + </div> |
| 44 | + `, |
| 45 | + imports: [PdfViewerModule], |
| 46 | + providers: [ToolbarService, AnnotationService] |
| 47 | +}) |
| 48 | +export class AppComponent { |
| 49 | + |
| 50 | + public document: string = |
| 51 | + 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf'; |
| 52 | + |
| 53 | + public resource: string = |
| 54 | + 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib'; |
| 55 | +} |
| 56 | + |
| 57 | +{% endhighlight %} |
| 58 | +{% endtabs %} |
| 59 | + |
| 60 | +## Add Area Annotation |
| 61 | + |
| 62 | +### Add Area Using the Toolbar |
| 63 | + |
| 64 | +1. Open the **Annotation Toolbar**. |
| 65 | +2. Select **Measurement** → **Area**. |
| 66 | +3. Click points to define the polygon; double‑click to close and finalize the area. |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +> **Tip:** If Pan mode is active, choosing a measurement tool switches the viewer into the appropriate interaction mode for a smoother workflow. |
| 71 | +
|
| 72 | +### Enable Area Mode |
| 73 | +Programmatically switch the viewer into Area mode. |
| 74 | + |
| 75 | +{% tabs %} |
| 76 | +{% highlight ts tabtitle="Standalone" %} |
| 77 | +enableAreaMode(): void { |
| 78 | + const pdfViewer = (document.getElementById('pdfViewer') as any).ej2_instances[0]; |
| 79 | + pdfViewer.annotationModule.setAnnotationMode('Area'); |
| 80 | +} |
| 81 | +{% endhighlight %} |
| 82 | +{% endtabs %} |
| 83 | + |
| 84 | +#### Exit Area Mode |
| 85 | +{% tabs %} |
| 86 | +{% highlight ts tabtitle="Standalone" %} |
| 87 | +exitAreaMode(): void { |
| 88 | + const pdfViewer = (document.getElementById('pdfViewer') as any).ej2_instances[0]; |
| 89 | + pdfViewer.annotationModule.setAnnotationMode('None'); |
| 90 | +} |
| 91 | +{% endhighlight %} |
| 92 | +{% endtabs %} |
| 93 | + |
| 94 | +### Add Area Programmatically |
| 95 | +Use the [`addAnnotation`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#addannotation) API to draw an area by providing **vertexPoints** for a closed region. |
| 96 | + |
| 97 | +{% tabs %} |
| 98 | +{% highlight ts tabtitle="Standalone" %} |
| 99 | +addArea(): void { |
| 100 | + const pdfViewer = (document.getElementById('pdfViewer') as any).ej2_instances[0]; |
| 101 | + |
| 102 | + pdfViewer.annotation.addAnnotation('Area', { |
| 103 | + offset: { x: 200, y: 500 }, |
| 104 | + pageNumber: 1, |
| 105 | + vertexPoints: [ |
| 106 | + { x: 200, y: 500 }, |
| 107 | + { x: 288, y: 499 }, |
| 108 | + { x: 289, y: 553 }, |
| 109 | + { x: 200, y: 500 } |
| 110 | + ] |
| 111 | + }); |
| 112 | +} |
| 113 | +{% endhighlight %} |
| 114 | +{% endtabs %} |
| 115 | + |
| 116 | +## Customize Area Appearance |
| 117 | +Configure default properties using the [`Area Settings`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#areasettings) property (for example, default **fill color**, **stroke color**, **opacity**). |
| 118 | + |
| 119 | +{% tabs %} |
| 120 | +{% highlight ts tabtitle="Standalone" %} |
| 121 | +import { Component } from '@angular/core'; |
| 122 | +import { |
| 123 | + PdfViewerModule, |
| 124 | + ToolbarService, |
| 125 | + AnnotationService |
| 126 | +} from '@syncfusion/ej2-angular-pdfviewer'; |
| 127 | + |
| 128 | +@Component({ |
| 129 | + selector: 'app-root', |
| 130 | + template: ` |
| 131 | + <div class="content-wrapper"> |
| 132 | + <ejs-pdfviewer |
| 133 | + id="pdfViewer" |
| 134 | + [documentPath]="document" |
| 135 | + [resourceUrl]="resource" |
| 136 | + [areaSettings]="areaSettings" |
| 137 | + style="height:650px;display:block"> |
| 138 | + </ejs-pdfviewer> |
| 139 | + </div> |
| 140 | + `, |
| 141 | + imports: [PdfViewerModule], |
| 142 | + providers: [ToolbarService, AnnotationService] |
| 143 | +}) |
| 144 | +export class AppComponent { |
| 145 | + |
| 146 | + public document: string = |
| 147 | + 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf'; |
| 148 | + |
| 149 | + public resource: string = |
| 150 | + 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib'; |
| 151 | + |
| 152 | + // Area annotation default settings |
| 153 | + public areaSettings = { |
| 154 | + fillColor: 'yellow', |
| 155 | + strokeColor: 'orange', |
| 156 | + opacity: 0.6 |
| 157 | + }; |
| 158 | +} |
| 159 | +`` |
| 160 | +{% endhighlight %} |
| 161 | +{% endtabs %} |
| 162 | + |
| 163 | +## Manage Area (Move, Reshape, Edit, Delete) |
| 164 | +- **Move**: Drag inside the polygon to reposition it. |
| 165 | +- **Reshape**: Drag any vertex handle to adjust points and shape. |
| 166 | + |
| 167 | +### Edit Perimeter |
| 168 | + |
| 169 | +#### Edit Perimeter (UI) |
| 170 | + |
| 171 | +- Edit the **fill color** using the Edit Color tool. |
| 172 | +  |
| 173 | +- Edit the **stroke color** using the Edit Stroke Color tool. |
| 174 | +  |
| 175 | +- Edit the **border thickness** using the Edit Thickness tool. |
| 176 | +  |
| 177 | +- Edit the **opacity** using the Edit Opacity tool. |
| 178 | +  |
| 179 | +- Open **Right Click → Properties** for additional line‑based options. |
| 180 | +  |
| 181 | + |
| 182 | +#### Edit Area Programmatically |
| 183 | + |
| 184 | +Update properties and call `editAnnotation()`. |
| 185 | + |
| 186 | +{% tabs %} |
| 187 | +{% highlight ts tabtitle="Standalone" %} |
| 188 | +editAreaProgrammatically(): void { |
| 189 | + const pdfViewer = (document.getElementById('pdfViewer') as any).ej2_instances[0]; |
| 190 | + |
| 191 | + for (const annotation of pdfViewer.annotationCollection) { |
| 192 | + if (annotation.subject === 'Area calculation') { |
| 193 | + annotation.strokeColor = '#0000FF'; |
| 194 | + annotation.thickness = 2; |
| 195 | + annotation.fillColor = '#FFFF00'; |
| 196 | + |
| 197 | + pdfViewer.annotation.editAnnotation(annotation); |
| 198 | + break; |
| 199 | + } |
| 200 | + } |
| 201 | +} |
| 202 | +{% endhighlight %} |
| 203 | +{% endtabs %} |
| 204 | + |
| 205 | +### Delete Distance Annotation |
| 206 | + |
| 207 | +Delete Distance Annotation via UI (toolbar/context menu) or programmatically. For supported workflows and APIs, see [**Delete Annotation**](../remove-annotations). |
| 208 | + |
| 209 | +## Set Default Properties During Initialization |
| 210 | +Apply defaults for Area using the [`areaSettings`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#areasettings) property. |
| 211 | + |
| 212 | +{% tabs %} |
| 213 | +{% highlight ts tabtitle="Standalone" %} |
| 214 | +import { Component } from '@angular/core'; |
| 215 | +import { |
| 216 | + PdfViewerModule, |
| 217 | + ToolbarService, |
| 218 | + AnnotationService |
| 219 | +} from '@syncfusion/ej2-angular-pdfviewer'; |
| 220 | + |
| 221 | +@Component({ |
| 222 | + selector: 'app-root', |
| 223 | + template: ` |
| 224 | + <div class="content-wrapper"> |
| 225 | + <ejs-pdfviewer |
| 226 | + id="pdfViewer" |
| 227 | + [documentPath]="document" |
| 228 | + [resourceUrl]="resource" |
| 229 | + [areaSettings]="areaSettings" |
| 230 | + style="height:650px;display:block"> |
| 231 | + </ejs-pdfviewer> |
| 232 | + </div> |
| 233 | + `, |
| 234 | + imports: [PdfViewerModule], |
| 235 | + providers: [ToolbarService, AnnotationService] |
| 236 | +}) |
| 237 | +export class AppComponent { |
| 238 | + |
| 239 | + public document: string = |
| 240 | + 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf'; |
| 241 | + |
| 242 | + public resource: string = |
| 243 | + 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib'; |
| 244 | + |
| 245 | + // Area annotation default settings |
| 246 | + public areaSettings = { |
| 247 | + fillColor: 'yellow', |
| 248 | + strokeColor: 'orange', |
| 249 | + opacity: 0.6 |
| 250 | + }; |
| 251 | +} |
| 252 | +{% endhighlight %} |
| 253 | +{% endtabs %} |
| 254 | + |
| 255 | +## Set Properties While Adding Individual Annotation |
| 256 | +Pass per‑annotation values directly when calling [`addAnnotation`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#addannotation). |
| 257 | + |
| 258 | +{% tabs %} |
| 259 | +{% highlight ts tabtitle="Standalone" %} |
| 260 | +addStyledArea(): void { |
| 261 | + const pdfViewer = (document.getElementById('pdfViewer') as any).ej2_instances[0]; |
| 262 | + |
| 263 | + pdfViewer.annotation.addAnnotation('Area', { |
| 264 | + offset: { x: 210, y: 510 }, |
| 265 | + pageNumber: 1, |
| 266 | + vertexPoints: [ |
| 267 | + { x: 210, y: 510 }, |
| 268 | + { x: 300, y: 510 }, |
| 269 | + { x: 305, y: 560 }, |
| 270 | + { x: 210, y: 510 } |
| 271 | + ], |
| 272 | + strokeColor: '#EA580C', |
| 273 | + fillColor: '#FEF3C7', |
| 274 | + thickness: 2, |
| 275 | + opacity: 0.85 |
| 276 | + }); |
| 277 | +} |
| 278 | +{% endhighlight %} |
| 279 | +{% endtabs %} |
| 280 | + |
| 281 | +## Scale Ratio and Units |
| 282 | +- Use **Scale Ratio** from the context menu to set the actual‑to‑page scale. |
| 283 | +  |
| 284 | +- Supported units include **Inch, Millimeter, Centimeter, Point, Pica, Feet**. |
| 285 | +  |
| 286 | + |
| 287 | +### Set Default Scale Ratio During Initialization |
| 288 | +Configure scale defaults using [`measurementSettings`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#mesaurementsettings). |
| 289 | + |
| 290 | +{% tabs %} |
| 291 | +{% highlight ts tabtitle="Standalone" %} |
| 292 | +import { Component } from '@angular/core'; |
| 293 | +import { |
| 294 | + PdfViewerModule, |
| 295 | + ToolbarService, |
| 296 | + AnnotationService |
| 297 | +} from '@syncfusion/ej2-angular-pdfviewer'; |
| 298 | + |
| 299 | +@Component({ |
| 300 | + selector: 'app-root', |
| 301 | + template: ` |
| 302 | + <div class="content-wrapper"> |
| 303 | + <ejs-pdfviewer |
| 304 | + id="pdfViewer" |
| 305 | + [documentPath]="document" |
| 306 | + [resourceUrl]="resource" |
| 307 | + [measurementSettings]="measurementSettings" |
| 308 | + style="height:640px;display:block"> |
| 309 | + </ejs-pdfviewer> |
| 310 | + </div> |
| 311 | + `, |
| 312 | + imports: [PdfViewerModule], |
| 313 | + providers: [ToolbarService, AnnotationService] |
| 314 | +}) |
| 315 | +export class AppComponent { |
| 316 | + |
| 317 | + public document: string = |
| 318 | + 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf'; |
| 319 | + |
| 320 | + public resource: string = |
| 321 | + 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib'; |
| 322 | + |
| 323 | + // Area / Measurement configuration |
| 324 | + public measurementSettings = { |
| 325 | + scaleRatio: 2, |
| 326 | + conversionUnit: 'cm', |
| 327 | + displayUnit: 'cm' |
| 328 | + }; |
| 329 | +} |
| 330 | + |
| 331 | +{% endhighlight %} |
| 332 | +{% endtabs %} |
| 333 | + |
| 334 | +## Handle Area Events |
| 335 | + |
| 336 | +Listen to annotation life-cycle events (add/modify/select/remove). For the full list and parameters, see [**Annotation Events**](../annotation-event). |
| 337 | + |
| 338 | +## Export and Import |
| 339 | +Area measurements can be exported or imported with other annotations. For workflows and supported formats, see [**Export and Import annotations**](../export-import-annotations). |
| 340 | + |
| 341 | +## See Also |
| 342 | +- [Annotation Toolbar](../../toolbar-customization/annotation-toolbar) |
| 343 | +- [Customize Context Menu](../../context-menu/custom-context-menu) |
| 344 | +- [Comments Panel](../comments) |
| 345 | +- [Annotation Events](../annotation-event) |
| 346 | +- [Export and Import annotations](../export-import-annotations) |
| 347 | +- [Delete Annotations](../remove-annotations) |
0 commit comments