【发布时间】:2020-09-27 17:22:02
【问题描述】:
我想在 PDFTron 中使用 SVG 创建自定义图章注释。
我在某个谷歌论坛上看到有人有同样的问题,一位 PDFTron 开发人员实际上做出了回应,这就是我目前所拥有的......
const svgElement = '<svg>my svg</svg>'
const CustomStamp = function() {
Annotations.StampAnnotation.call(this);
this.ImageData = encodeURI('data:image/svg+xml,' + svgElement);
}
CustomStamp.prototype = new Annotations.StampAnnotation();
const CustomCreateTool = function(docViewer) {
Tools.GenericAnnotationCreateTool.call(this, docViewer, CustomStamp);
};
CustomCreateTool.prototype = new Tools.GenericAnnotationCreateTool();
CustomCreateTool.prototype.mouseLeftDown = function() {
Tools.AnnotationSelectTool.prototype.mouseLeftDown.apply(this, arguments);
};
CustomCreateTool.prototype.mouseMove = function() {
Tools.AnnotationSelectTool.prototype.mouseMove.apply(this, arguments);
};
CustomCreateTool.prototype.mouseLeftUp = function(e) {
var annotation;
Tools.GenericAnnotationCreateTool.prototype.mouseLeftDown.call(this, e);
if (this.annotation) {
this.annotation.Width = 50;
this.annotation.Height = 50;
this.annotation.X -= this.annotation.Width/2;
this.annotation.Y -= this.annotation.Height/2;
this.annotation.NoResize = true;
annotation = this.annotation;
}
Tools.GenericAnnotationCreateTool.prototype.mouseLeftUp.call(this, e);
if (annotation) {
annotManager.redrawAnnotation(annotation);
}
但是,它似乎只绘制了一个空框...任何帮助将不胜感激!
【问题讨论】: