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.
And when I hardcode the mouse coordinates for the bottom left corner the preview is then drawn from the start.
So the question(s):
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.
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?
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:
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:
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.