Skip to content

Commit f8466c9

Browse files
committed
[Editor] Add a Rect entry to a saved popup in order to avoid to have an invalid pdf
1 parent 212547e commit f8466c9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/display/editor/editor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,18 @@ class AnnotationEditor {
12131213

12141214
addComment(serialized) {
12151215
if (this.hasEditedComment) {
1216+
const DEFAULT_POPUP_WIDTH = 180;
1217+
const DEFAULT_POPUP_HEIGHT = 100;
1218+
const [, , , trY] = serialized.rect;
1219+
const [pageWidth] = this.pageDimensions;
1220+
const [pageX] = this.pageTranslation;
1221+
const blX = pageX + pageWidth + 1;
1222+
const blY = trY - DEFAULT_POPUP_HEIGHT;
1223+
const trX = blX + DEFAULT_POPUP_WIDTH;
12161224
serialized.popup = {
12171225
contents: this.comment.text,
12181226
deleted: this.comment.deleted,
1227+
rect: [blX, blY, trX, trY],
12191228
};
12201229
}
12211230
}

test/unit/annotation_spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4995,6 +4995,7 @@ describe("annotation", function () {
49954995
rotation: 90,
49964996
popup: {
49974997
contents: "Hello PDF.js World !",
4998+
rect: [1, 2, 3, 4],
49984999
},
49995000
id: "143R",
50005001
ref: highlightRef,
@@ -5010,7 +5011,7 @@ describe("annotation", function () {
50105011
const popup = data[0];
50115012
expect(popup.data).toEqual(
50125013
"1 0 obj\n" +
5013-
"<< /Type /Annot /Subtype /Popup /Open false /Parent 143 0 R>>\n" +
5014+
"<< /Type /Annot /Subtype /Popup /Open false /Rect [1 2 3 4] /Parent 143 0 R>>\n" +
50145015
"endobj\n"
50155016
);
50165017

0 commit comments

Comments
 (0)