Tap and Tap Behaviour for creating Arrow, Line and Ruler Annotation

We are using pdftron in our application for drawing annotations, We would like to replace the current behaviour of PTCreateToolBase which is ‘Tap-Drag’ with ‘Tap-Tap’ to create annotation, The reason behind doing so is we want our users to accurately pick a starting point and zoom out and scroll to his desired second point and tap again to complete the action of creating Arrow or Line or Ruler Annotation

I create my own annotation creation tool by deriving the PTCreateToolBase class, But when I try to use api ‘HandleTap’ like below

`
[Export(“pdfViewCtrl:handleTap:”)]
public bool HandleTap(PTPDFViewCtrl pdfViewCtrl, UITapGestureRecognizer gestureRecognizer)
{
/// The Logic of Tap and Tap behaviour

}
`

But that method is not getting called

Below is the code snippet I used for changing the tool

toolManager.ChangeTool(new Class(typeof(CustomLine)));

Do somebody know what I am doing wrong here?

Or is there any-other way to achieve the Tap and Tap behaviour for creating Annotation

Hi Vignesh,

Without access to all the code, it’s difficult to say with certainty what is occurring.

Are you receiving the first tap event, but not the second? If so, make sure you are returning “true” to prevent the tool from automatically switching back to the pan tool after the first tap.

If you are not receiving the first tap, it is harder to reason what might be occurring. As a test, if subclass the line tools and override nothing, does it function as a normal line tool?

Hi James,

I managed to create Tap and Tap behaviour using Toolmanager’s HandleTap event handler, But I got stuck in adding a customised icon at a tapping point

I try to use circle annotation But the problem is that Annotation type is zooming along with the pdf zoom scale

Circle circle = Circle.Create(_pdfDoc, rct); circle.SetColor(new ColorPt(1, 0, 0)); circle.SetInteriorColor(new ColorPt(1, 0, 0), 3);

Then I tried to add icon like the below code snippet

ElementBuilder build = new ElementBuilder(); ElementWriter writer = new ElementWriter(); writer.Begin(_pdfDoc); string Path = NSBundle.MainBundle.PathForAuxiliaryExecutable("ic_line_white_24.png"); Console.WriteLine("Before Image initialization img Path={0}", Path); Image img = Image.Create(_pdfDoc, Path); if (img == null) Console.WriteLine("Image icon is null"); else Console.WriteLine("Image icon is not null"); int w = img.GetImageWidth(), h = img.GetImageHeight(); Element img_element = build.CreateImage(img, 0, 0, w, h); writer.WritePlacedElement(img_element); Obj appearance_stream = writer.End(); appearance_stream.PutRect("BBox", 0, 0, w, h); annotation.SetAppearance(appearance_stream);

But the line Image img = Image.Create(_pdfDoc, Path); is throwing below Exception

pdftron.Common.PDFNetException: Exception:
Message: Failed to embed PNG image
Conditional expression: result->IsValid()
Version : 6.10.3.70597
Filename : Image.cpp
Function : Create
Linenumber : 72

Is there any-other ways to add an endpoint icon like annotation exactly at the tapping area?

Hi Vignesh,

The simplest way to create an image where a user taps is to replace the standard sticky note icon with an image. There is sample code for doing so inside the tools source code - in PTCreateToolBase.m, search for the comment “// sample code for a custom sticky note icon.”, and uncomment the code below it. As the comment indicates, please make sure no further calls to “RefreshAppearance” are made, or the image will be replaced with a standard sticky note icon.

Note that if you do not want the note popup to display, set the following boolean to false:

https://www.pdftron.com/api/ios/Classes/PTTextAnnotationOptions.html#/c:objc(cs)PTTextAnnotationOptions(py)opensPopupOnTap

Please let me know if this helps,

James

Hi James,

Thanks for the response .But The code snippet is still not working for me

ElementBuilder build = new ElementBuilder(); ElementWriter writer = new ElementWriter(); writer.Begin(_pdfDoc,false); string path = NSBundle.MainBundle.PathForResource("ic_info_grey_tap", "png"); Image image = Image.Create(_pdfDoc, path); if (image == null) Console.WriteLine("Image icon is null"); else Console.WriteLine("Image icon is not null"); int w = image.GetImageWidth(), h = image.GetImageHeight(); Element img_element = build.CreateImage(image, 0, 0, w, h); writer.WritePlacedElement(img_element); Obj appearance_stream = writer.End(); appearance_stream.PutRect("BBox", 0, 0, w, h); annotation.SetAppearance(appearance_stream);

But Still I am getting the same exception like below

`
The exception while setting icon pdftron.Common.PDFNetException: Exception:
Message: Failed to embed PNG image
Conditional expression: result->IsValid()
Version : 6.10.3.70597
Filename : Image.cpp
Function : Create
Linenumber : 72

at pdftron.Common.PDFNetException.REX (System.IntPtr result) [0x00013] in <3d51abe1660b4d92a6ac14082ab464fc>:0
at pdftron.PDF.Image.Create (pdftron.SDF.SDFDoc doc, System.String filename, pdftron.SDF.Obj encoder_hints) [0x00036] in <3d51abe1660b4d92a6ac14082ab464fc>:0
at pdftron.PDF.Image.Create (pdftron.SDF.SDFDoc doc, System.String filename) [0x00000] in <3d51abe1660b4d92a6ac14082ab464fc>:0
`

Hi Vignesh,

I notice that you are loading the PNG from the main bundle. Have you turned off PNG optimization? This option causes the PNG to be modified such that it will still work with Apple APIs, but as it ceases to actually be a PNG, is no longer compatible with APIs that expect true PNGs, including those in PDFTron.

Please let me know if this helps.

James Borthwick
PDFTron