ToolManager.CreateTool for Stamp

Product: PDFNetDotNet4

Product Version: 9.4.28.734

Please give a brief summary of your issue:
ToolManager.CreateTool for Stamp

Please describe your issue and provide steps to reproduce it:
We need to give our users the ability to draw rubber stamps on a document. We have a preset list of words on the stamp “APPROVED”, “REVIEW”, etc., plus the user’s name and date of stamp below this. Currently I’m using the following code to do this:

private void StampPage(string stampText)
{
using (var s = new Stamper(Stamper.SizeType.e_absolute_size, 20, 20))
{
var currentPage = _pdfViewer.Current_View.GetCurrentPage();
var doc = _pdfViewer.GetPDFDoc();
var pg = doc.GetPage(currentPage);
var cropBox = pg.GetCropBox();

            s.SetOpacity(1);
            //s.SetRotation(45);
            s.SetAsBackground(true);

            s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_top);
            s.SetPosition(40, 40);
            s.SetSize(Stamper.SizeType.e_absolute_size, 100, 100);
            s.SetAsAnnotation(true);
            var stamp = CreateStamp(stampText);

            var img = pdftron.PDF.Image.Create(doc.GetSDFDoc(), stamp);
            s.StampImage(doc, img, new PageSet(currentPage));

        }

        _pdfViewer.Current_View.Update(true);
    }

The stamp gets created and placed on a hard-coded area of the document when the user clicks a button. But we are being requested to allow the user to draw the stamp by using mouse gestures, like we had before with our older product (prior to using PdfTron). Please see the attached screen clip. We would like it to work similar to how the ToolManager.CreateTool works, like this:

PDFViewViewer view = GetCurrentViewer();
if (view != null)
{
view.ToolManager.AnnotationAdded += ToolManager_AnnotationAdded;

            view.ToolManager.CreateTool(pdftron.PDF.Tools.ToolManager.ToolType.e_rect_create, null, true);
        }

But with our own custom stamp, preferably with a solid color border, some text in the middle of it, and transparent background inside the rectangle.
CogniVision Workspace 2023-02-17 13-55-27.zip (3.0 MB)

Thank you for contacting us about this.

Just to clarify, are you using PDFView or PDFViewWPF? With the latter, it is possible to extend annotation classes to create your own custom stamp annotation to achieve your custom watermark that can be drawn like a rectangle.

You can extend the SimpleShapeCreate.cs class to create this custom tool, which then you can use by calling the CreateTool method from the viewer.

I am using the PDFViewWPF control. Yes, I see how properties can be overridden within the CreateTool method. But how would preset text get drawn within the rectangle annotation at the time of creation, in a way that it gets stretched or shrunk based on the height and width of the user-drawn annotation?