PDF.js Express Version
7.3.0
Detailed description of issue
I have created a custom draw handler for using a Perimeter tool for just 2 point click draw. And another custom handler for drawing perimeter annotations with arc ends joining the edges of the 2 lines like this -
As soon as I call setCustomDrawHandler while drawing Perimeter annotation, webveiwer throws this error - INVALID PDF STRUCTURE
Code snippet of following - SAME GIVEN BELOW.
const { Annotations, docViewer } = this.viewerInstance;
Annotations.setCustomDrawHandler(Annotations.PolylineAnnotation, function(
ctx,
pageMatrix,
rotation,
{ annotation, originalDraw }
) {
originalDraw(ctx, pageMatrix);
const paths = annotation.getPath();
if (paths.length === 3) {
const tool = docViewer.getTool(AnnotationTools.PERIMETER);
const ke = new KeyboardEvent(‘keydown’, {
bubbles: true, cancelable: true
});
tool.mouseDoubleClick(ke);
}
const { StrokeThickness, StrokeColor } = annotation;
for (let i = 1; i < paths.length - 1; i++) {
const { x, y } = paths[i];
ctx.beginPath();
ctx.arc(x, y, StrokeThickness * 3, 0, 2 * Math.PI, false);
ctx.fillStyle = StrokeColor.toHexString();
ctx.fill();
}
});
Also Tried this -
Expected behaviour
Earlier it was working properly in 7.1.2.
Does your issue happen with every document, or just one?
Every Document
Code snippet
const { Annotations, docViewer } = this.viewerInstance;
Annotations.setCustomDrawHandler(Annotations.PolylineAnnotation, function(
ctx,
pageMatrix,
rotation,
{ annotation, originalDraw }
) {
originalDraw(ctx, pageMatrix);
const paths = annotation.getPath();
if (paths.length === 3) {
const tool = docViewer.getTool(AnnotationTools.PERIMETER);
const ke = new KeyboardEvent('keydown', {
bubbles: true, cancelable: true
});
tool.mouseDoubleClick(ke);
}
});
Please let us know its solution ASAP.