Merge pull request #20179 from calixteman/add_rect_popup

[Editor] Add a Rect entry to a saved popup in order to avoid to have an invalid pdf
This commit is contained in:
calixteman 2025-08-24 12:01:31 +02:00 committed by GitHub
commit 592d6c070a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -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],
};
}
}

View File

@ -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"
);