Creating a new tool

In this document
chevron_rightIn Xamarin.Android
chevron_rightIn Xamarin.iOS

linkIn Xamarin.Android

Creating a new tool in Xamarin.Android is similar to creating a new tool in Android. See tutorial here.

For example, the equivalent of the example provided in the Android guide will be:

  1. Creating CustomTool:
using System;

using pdftron.PDF;
using pdftron.PDF.Tools;
using pdftron.PDF.Tools.Utils;

using Polygon = pdftronprivate.PDF.Annots.Polygon;

namespace PDFNetAndroidXamarinSample
{
    public class CustomTool : RectCreate
    {
        public static ToolManager.IToolModeBase MODE = ToolManager.ToolMode.AddNewMode((int)Annot.Type.e_Polygon);

        public CustomTool(PDFViewCtrl ctrl) : base(ctrl)
        {

        }

        public override ToolManager.IToolModeBase ToolMode
        {
            get
            {
                return MODE;
            }
        }

        protected override pdftronprivate.PDF.Annot CreateMarkup(pdftronprivate.PDF.PDFDoc doc, pdftronprivate.PDF.Rect bbox)
        {
            var poly = new Polygon(Polygon.Create(doc, (int)Annot.Type.e_Polygon, bbox));
            var color = Utils.Color2ColorPt(Android.Graphics.Color.Red);
            poly.SetColor(color, 3);
            poly.SetVertex(0, new pdftronprivate.PDF.Point(bbox.X1, bbox.Y1));
            poly.SetVertex(1, new pdftronprivate.PDF.Point(bbox.X1, bbox.Y2));
            poly.SetVertex(2, new pdftronprivate.PDF.Point(bbox.X2, bbox.Y2));
            poly.SetVertex(3, new pdftronprivate.PDF.Point(bbox.X2, bbox.Y1));
            poly.IntentName = pdftronprivate.PDF.Annots.PolyLine.EPolygonCloud;
            poly.BorderEffect = pdftronprivate.PDF.Annots.Markup.ECloudy;
            poly.BorderEffectIntensity = 2.0;
            poly.Rect = bbox;

            return poly;
        }
    }
}
  1. Using the tool:
mToolManager.Tool = new CustomTool(mPdfViewCtrl);

linkIn Xamarin.iOS

It is possible to create a new tool via C# API if you are looking for very simple tools that do not require much UI. Otherwise, you will have to customize the tools source code in Objective-C. The following section describes how to create a simple tool via C# API.

  1. Creating CustomTool:
using System;
using ObjCRuntime;
using pdftron.PDF;

namespace PDFNetiOSXamarinSample
{
    public class CustomTool : pdftron.PDF.Tools.CreateToolBase
    {
        public CustomTool(PDFViewCtrl ctrl) : base(ctrl)
        {
        }

        public override bool CreatesAnnotation
        {
            get
            {
                return true;
            }
        }

        public override Class AnnotClass
        {
            get
            {
                return new Class(typeof(pdftronprivate.PTRedactionAnnot));
            }
        }
    }

}
  1. Using the tool:
mToolManager.Tool = new CustomTool(mPdfViewCtrl);

To learn more about how to modify the tools source code in Objective-C, check out this guide: Creating a new tool.