GenericAnnotationCreateTool start drawing by default

Product: ApryseSDK TypeScript

Product Version: 10.12.0

Please give a brief summary of your issue:
I’m trying to make a custom tool to display a set of annotations to paste.

Please describe your issue and provide steps to reproduce it:
I was able to create a custom tool using GenericAnnotationCreateTool. And the preview is working but only when I do drag/drop type of annot creation or by clicking first. Is it possible to programatically initiate first point click? Was trying to do this but no luck so far. And also because I use annot.draw(ctx, pageMatrix) function to preview geometries I noticed that if I don’t click at the bottom right corner first to start the preview. The preview is stopped at the clicked point.

Hope it will be more clear in the video.

You can see that the preview annot is only rendered up to the point when I click with my custom tool.
I would like it to use whole surface of the PDF page.

1 Like

Hi there,

Please see this forum post for general implementation details:

You will need to use the mouseMove to position the preview as the cursor moves.

Is it possible to programatically initiate first point click?

If it is on the documentViewer, you can use the mouseLeftUp event:
https://docs.apryse.com/api/web/Core.DocumentViewer.html#event:mouseLeftUp__anchor
For a generic tool, you can use the mouseLeftUp method:
https://docs.apryse.com/api/web/Core.Tools.GenericAnnotationCreateTool.html#mouseLeftUp__anchor

Best regards,
Kevin Kim

1 Like

Kevin,

Thank you for a quick response.

I actually made some progress on this, but still have a question.
I added this to switchIn event on my custom tool

const adjustedMouseEvent = new MouseEvent('click', {
    buttons: 1,
    clientX: 900,
    clientY: 735,
    screenX: -951,
    screenY: 1025,
});
console.log('switchIn adjustedMove: ', adjustedMouseEvent);
Tools.GenericAnnotationCreateTool.prototype.mouseLeftUp.call(
    this,
    adjustedMouseEvent,
);
Tools.GenericAnnotationCreateTool.prototype.mouseLeftDown.call(
    this,
    adjustedMouseEvent,
);

And when I hardcode the mouse coordinates for the bottom left corner the preview is then drawn from the start.

So the question(s):

  1. Is it possible to force annotation preview drawing in some other way instead of emulating 1st mouse click? Basically I want the tool to behave just like RubberStampCreateTool. As soon as the RubberStampCreateTool tool is activated you can see the stamp preview you are going to place. My tool needs the same, but is expanded from GenericAnnotationCreateTool.
  2. If it is not possible to set it up and I’m stuck with emulating mouse click. How can I get the correct mouse coordinates to pass into my custom tool to emulate the click. The reason I need to emulate bottom left click is because of my initial post. So that the whole page area is used for drawing preview.

p.s. Extra note for clarity:
I’m not drawing annotations like in your Creating custom annotations for your viewer example via ctx.moveTo, ctx.lineTo etc.
But I have in memory Annotations which are drawn as annot.draw(ctx, pageMatrix) and in this case unless I first click at the bottom right corner of the page not all page will be used for rendering. Looks like some kind of draw envelope is set internally?

regards

1 Like

Thank you for the information.

1 Like

Hi there,

  1. Is it possible to force annotation preview drawing in some other way instead of emulating 1st mouse click? Basically I want the tool to behave just like RubberStampCreateTool. As soon as the RubberStampCreateTool tool is activated you can see the stamp preview you are going to place. My tool needs the same, but is expanded from GenericAnnotationCreateTool.

Because the GenericAnnotationCreateTool doesn’t have the same preview implementation, you would need to extend the RubberStampCreateTool for the stamp preview behaviour.
See this guide for extending existing tools:

  1. If it is not possible to set it up and I’m stuck with emulating mouse click. How can I get the correct mouse coordinates to pass into my custom tool to emulate the click. The reason I need to emulate bottom left click is because of my initial post. So that the whole page area is used for drawing preview.

You can get the dimensions of the documentViewer via
getPageWidth(1) // where 1 is the page number
getPageHeight(1)

Since the top right of the corner is (0, 0) coordinate, the bottom left corner would be (0, getPageHeight(1))

Please see our coordinates guide for more details:

Best regards,
Kevin Kim

1 Like

Kevin,

Sorry, was away on holiday.

I had a look into this and I’m having problems removing stamp preview and drawing my own geometries. I don’t see any draw function code triggered that I added.

Do you have any sample code specifically on making custom tool from RubberStampCreateTool?
As far as I can see none of the draw functions are called like with GenericAnnotationCreateTool sample code that i looked at.

regards

1 Like

Kevin,

Can we open a ticket for this please,
I would like to share the code so that way maybe we can solve it faster.

regards

1 Like

Hi there,

You can open a ticket via the support portal at

Best regards,
Kevin Kim

2 Likes