diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index 3c58ba1f3..1d282ebe9 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -1213,9 +1213,18 @@ class AnnotationEditor { addComment(serialized) { if (this.hasEditedComment) { + const DEFAULT_POPUP_WIDTH = 180; + const DEFAULT_POPUP_HEIGHT = 100; + const [, , , trY] = serialized.rect; + const [pageWidth] = this.pageDimensions; + const [pageX] = this.pageTranslation; + const blX = pageX + pageWidth + 1; + const blY = trY - DEFAULT_POPUP_HEIGHT; + const trX = blX + DEFAULT_POPUP_WIDTH; serialized.popup = { contents: this.comment.text, deleted: this.comment.deleted, + rect: [blX, blY, trX, trY], }; } } diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 46617e5ba..ca728571b 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -4995,6 +4995,7 @@ describe("annotation", function () { rotation: 90, popup: { contents: "Hello PDF.js World !", + rect: [1, 2, 3, 4], }, id: "143R", ref: highlightRef, @@ -5010,7 +5011,7 @@ describe("annotation", function () { const popup = data[0]; expect(popup.data).toEqual( "1 0 obj\n" + - "<< /Type /Annot /Subtype /Popup /Open false /Parent 143 0 R>>\n" + + "<< /Type /Annot /Subtype /Popup /Open false /Rect [1 2 3 4] /Parent 143 0 R>>\n" + "endobj\n" );