Search results

Shape Annotation in ASP.NET Core PDF Viewer control

30 Jul 2021 / 3 minutes to read

The PDF Viewer control provides the options to add, edit, and delete the shape annotations. The shape annotation types supported in the PDF Viewer control are:

  • Line
  • Arrow
  • Rectangle
  • Circle
  • Polygon

ShapeAnnotation

Adding a shape annotation to the PDF document

Shape annotations can be added to the PDF document using the annotation toolbar.

  • Click the Edit Annotation button in the PDF Viewer toolbar. A toolbar appears below it.
  • Click the Shape Annotation drop-down button. A drop-down pop-up will appear and shows the shape annotations to be added.
  • Select the shape types to be added to the page in the drop-down pop-up. It enables the selected shape annotation mode.
  • You can add the shapes over the pages of the PDF document.

In the pan mode, if the shape annotation mode is entered, the PDF Viewer control will switch to text select mode.

ShapeTool

Refer to the following code sample to switch to the circle annotation mode.

Copied to clipboard
<!--Element to set shape annotation mode-->
<button id="set" onclick="addAnnot()">Circle</button>
<div style="width:100%;height:600px">
    <ejs-pdfviewer id="pdfviewer" style="height:600px" serviceUrl="/api/PdfViewer" documentPath=@ViewBag.DocumentPath>
    </ejs-pdfviewer>
</div>
<script>
    function addAnnot() {
        var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
        pdfViewer.annotation.setAnnotationMode('Circle');
    }
</script>

Editing the properties of the shape annotation

The fill color, stroke color, thickness, and opacity of the shape annotation can be edited using the Edit color tool, Edit stroke color tool, Edit thickness tool, and Edit opacity tool in the annotation toolbar.

Editing fill color

The fill color of the annotation can be edited using the color palette provided in the Edit Color tool.

ShapeFillColor

Editing stroke color

The stroke color of the annotation can be edited using the color palette provided in the Edit Stroke Color tool.

ShapeStrokeColor

Editing thickness

The thickness of the border of the annotation can be edited using the range slider provided in the Edit Thickness tool.

ShapeThickness

Editing opacity

The opacity of the annotation can be edited using the range slider provided in the Edit Opacity tool.

ShapeOpacity

Editing the line properties

The properties of the line shapes such as line and arrow annotations can be edited using the Line Properties window. It can be opened by selecting the Properties option in the context menu that appears on right-clicking the line and arrow annotations.

Refer to the following code sample to set the default annotation settings.

ShapeProperty

Setting default properties during the control initialization

The properties of the shape annotations can be set before creating the control using LineSettings, ArrowSettings, RectangleSettings, CircleSettings, and PolygonSettings.

Copied to clipboard
<div style="width:100%;height:600px">
    <ejs-pdfviewer id="pdfviewer" style="height:600px" serviceUrl="/api/PdfViewer" documentPath=@ViewBag.DocumentPath
                   lineSettings="@(new Syncfusion.EJ2.PdfViewer.PdfViewerLineSettings {FillColor="blue", Opacity=0.6, StrokeColor="green"})"
                   arrowSettings="@(new Syncfusion.EJ2.PdfViewer.PdfViewerArrowSettings {FillColor="green", Opacity=0.6, StrokeColor="blue"})"
                   rectangleSettings="@(new Syncfusion.EJ2.PdfViewer.PdfViewerRectangleSettings {FillColor="yellow", Opacity=0.6, StrokeColor="orange"})"
                   circleSettings="@(new Syncfusion.EJ2.PdfViewer.PdfViewerCircleSettings {FillColor="orange", Opacity=0.6, StrokeColor="pink"})"
                   polygonSettings="@(new Syncfusion.EJ2.PdfViewer.PdfViewerPolygonSettings {FillColor="pink", Opacity=0.6, StrokeColor="yellow"})">
    </ejs-pdfviewer>
</div>