this.toolModeMap[ToolMode.AnnotationCreateFreeText] = Tools.FreeTextCreateTool;
var Tools = window.Tools;
Tools.FreeTextCreateTool = function(docViewer) {
Tools.GenericAnnotationCreateTool.call(this, docViewer, Annotations.FreeTextAnnotation);
};
Tools.FreeTextCreateTool.prototype = $.extend(new Tools.GenericAnnotationCreateTool(), {
mouseLeftDown: function(e) {
if (!this.annotation) {
Tools.GenericAnnotationCreateTool.prototype.mouseLeftDown.call(this, e);
this.annotation.setContents("Text");
}
},
mouseMove: function(e) {
if (!this.annotation) {
return;
}
Tools.Tool.prototype.mouseMove.call(this, e);
if (typeof this.pageCoordinates === "undefined") {
return;
}
var pt0 = this.pageCoordinates[0];
var pt1 = this.pageCoordinates[1];
if (pt1 === null || pt0 === null || (pt0.pageIndex !== pt1.pageIndex)) {
return;
}
var rect = new Annotations.Rect(pt0.x, pt0.y, pt1.x, pt1.y);
rect.normalize();
this.annotation.setRect(rect);
this.annotation.setPadding(new Annotations.Rect(0, 0, 0, 0));
this.docViewer.GetAnnotationManager().RedrawAnnotation(this.annotation);
},
mouseLeftUp: function(e) {
Tools.Tool.prototype.mouseLeftUp.call(this, e);
if (this.annotation) {
var am = this.docViewer.GetAnnotationManager();
var w = this.annotation.GetWidth();
var h = this.annotation.GetHeight();
// delete if dimensions to small
if (w === 0 && h === 0) {
am.DeleteAnnotation(this.annotation);
} else {
this.annotation.setPadding(new Annotations.Rect(0, 0, 0, 0));
am.AddAnnotation(this.annotation);
}
this.annotation = null;
}
}
});
Hi Richard,The TextAnnotationCreateTool is actually just the base text tool that the highlight, underline and strikeout tools inherit from.What I think you're looking for is the FreeText annotation. In the current version there is no FreeTextCreateTool but it will be there in the next version and for now you can actually implement it yourself. Here are the steps:
1) In WebViewerInterface.js add AnnotationCreateFreeText: "AnnotationCreateFreeText" as a property on the exports.PDFTron.WebViewer.ToolMode object.2) In AnnotationPanel.html add an element to the toolModePicker element that has a data-toolmode of AnnotationCreateFreeText.
3) Add the following tool code in a config file: