Volume Annotation in ASP.NET Core PDF Viewer

14 Aug 20268 minutes to read

Volume measurement annotations allow users to draw circular regions and calculate the volume visually.

Volume overview

Enable Volume Measurement

Include the Annotation and Toolbar modules for the PDF Viewer to enable volume annotation tools.

<div style="width:100%;height:650px">
    <ejs-pdfviewer id="pdfviewer"
                   style="height:650px"
                   documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
                   resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib">
    </ejs-pdfviewer>
</div>

Add Volume Annotation

Draw Volume Using the Toolbar

  1. Open the Annotation Toolbar.
  2. Select Measurement → Volume.
  3. Click and drag on the page to draw the volume.

Measurement toolbar

If Pan mode is active, selecting the Volume tool automatically switches interaction mode.

Enable Volume Mode

Programmatically switch the viewer into Volume mode.

<script>
function enableVolumeMode() {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.annotation.setAnnotationMode('Volume');
}
</script>

Exit Volume Mode

<script>
function exitVolumeMode() {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.annotation.setAnnotationMode('None');
}
</script>

Add Volume Programmatically

Use the addAnnotation API to add a Volume measurement at a specific location.

<script>
function addVolume() {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.annotation.addAnnotation('Volume', {
    offset: { x: 200, y: 810 },
    pageNumber: 1,
    width: 90,
    height: 90
  });
}
</script>

Customize Volume Appearance

Configure default properties using the volumeSettings property (for example, default fill color, stroke color, opacity).

<div style="width:100%;height:650px">
    <ejs-pdfviewer id="pdfviewer"
                   style="height:650px"
                   documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
                   resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib">
    </ejs-pdfviewer>
</div>
<script>
window.onload = function () {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.volumeSettings = { fillColor: 'yellow', strokeColor: 'orange', opacity: 0.6 };
}
</script>

Manage Volume (Move, Resize, Delete)

  • Move: Drag inside the polygon to reposition it.
  • Reshape: Drag any vertex handle to adjust points and shape.

Edit Volume Annotation

Edit Volume (UI)

  • Edit the fill color using the Edit Color tool.
    Fill color
  • Edit the stroke color using the Edit Stroke Color tool.
    Stroke color
  • Edit the border thickness using the Edit Thickness tool.
    Thickness
  • Edit the opacity using the Edit Opacity tool.
    Opacity
  • Open Right Click → Properties for additional line‑based options.
    Line properties

Edit Volume Programmatically

Update properties and call editAnnotation().

<script>
function editVolumeProgrammatically() {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  var coll = viewer.annotationCollection || [];
  for (var i = 0; i < coll.length; i++) {
    var ann = coll[i];
    if (ann.subject === 'Volume calculation') {
      ann.strokeColor = '#0000FF';
      ann.thickness = 2;
      ann.opacity = 0.8;
      viewer.annotation.editAnnotation(ann);
      break;
    }
  }
}
</script>

Delete Volume Annotation

Delete Volume Annotation via UI (toolbar/context menu) or programmatically. For supported workflows and APIs, see Delete Annotation.

Set Default Properties During Initialization

Apply defaults for Volume using the volumeSettings property.

<div style="width:100%;height:650px">
    <ejs-pdfviewer id="pdfviewer"
                   style="height:650px"
                   documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
                   resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib">
    </ejs-pdfviewer>
</div>
<script>
window.onload = function () {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.volumeSettings = { fillColor: 'yellow', opacity: 0.6, strokeColor: 'yellow' };
}
</script>

Set Properties While Adding Individual Annotation

Apply defaults for Volume using the volumeSettings property.

<script>
function addStyledVolume() {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.annotation.addAnnotation('Volume', {
    offset: { x: 200, y: 810 },
    pageNumber: 1,
    width: 90,
    height: 90,
    fillColor: 'yellow',
    opacity: 0.6,
    strokeColor: 'yellow'
  });
}
</script>

Scale Ratio & Units

  • Use Scale Ratio from the context menu.
    Scale ratio
  • Supported units: Inch, Millimeter, Centimeter, Point, Pica, Feet.
    Scale dialog

Set Default Scale Ratio During Initialization

Configure scale defaults using measurementSettings.

<div style="width:100%;height:650px">
    <ejs-pdfviewer id="pdfviewer"
                   style="height:650px"
                   documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
                   resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib">
    </ejs-pdfviewer>
</div>
<script>
window.onload = function () {
  var viewer = document.getElementById('pdfviewer').ej2_instances[0];
  viewer.measurementSettings = { scaleRatio: 2, conversionUnit: 'cm', displayUnit: 'cm' };
}
</script>

Handle Volume Events

Listen to annotation life-cycle events (add/modify/select/remove). For the full list and parameters, see Annotation Events.

Export and Import

Volume measurements can be exported or imported with other annotations. For workflows and supported formats, see Export and Import annotations.

See Also