Thanks for the help. I've got the CreateTool going with the mouse events, but I don't think the mouse coordinates in the event are what I can use to place the field on the page... either that or I'm missing something else in my code. Here's the TypeScript code I have, maybe you can suggest something?
let startPoint: Point;
export const FormFieldCreateTool = function(docViewer: any) {
Tools.RectangleCreateTool.apply(this, arguments);
// Tools.RectangleCreateTool.call(this, docViewer, FormFieldAnnotation);
} as any as { new(docViewer: any): any; };
FormFieldCreateTool.prototype = $.extend(new Tools.RectangleCreateTool(), {
mouseLeftDown: function(e: any) {
startPoint = {
x: e.originalEvent.layerX,
y: e.originalEvent.layerY
};
console.log('mouse left down', arguments);
Tools.RectangleCreateTool.prototype.mouseLeftDown.apply(this, arguments);
},
mouseLeftUp: async function(e: any) {
console.log('mouse left up', arguments);
const docViewer = this.getDocumentViewer();
const pageNumber = docViewer.getCurrentPage();
const doc = docViewer.getDocument();
const pdfDoc = await doc.getPDFDoc();
pdfDoc.initSecurityHandler();
pdfDoc.lock();
const field = await pdfDoc.fieldCreateFromStrings('bar', FieldType.e_text, 'Bar', '');
console.log('field', field);
const annot = await PDFNet.WidgetAnnot.create(
pdfDoc,
await PDFNet.Rect.init(startPoint.x, startPoint.y, e.originalEvent.layerX, e.originalEvent.layerY),
field
);
const page = await pdfDoc.getPage(pageNumber);
console.log(page);
page.annotPushBack(annot);
pdfDoc.refreshFieldAppearances();
Tools.RectangleCreateTool.prototype.mouseLeftUp.apply(this, arguments);
}
});