diff --git a/src/modules/annotations.js b/src/modules/annotations.js index 4e44fdb12..2900c38f8 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -216,13 +216,13 @@ import { jsPDF } from "../jspdf.js"; rect = "/Rect [" + - getHorizontalCoordinateString(anno.x) + + anno.finalBounds.x + " " + - getVerticalCoordinateString(anno.y) + + anno.finalBounds.y + " " + - getHorizontalCoordinateString(anno.x + anno.w) + + anno.finalBounds.w + " " + - getVerticalCoordinateString(anno.y + anno.h) + + anno.finalBounds.h + "] "; line = ""; @@ -325,11 +325,16 @@ import { jsPDF } from "../jspdf.js"; */ jsPDFAPI.link = function(x, y, w, h, options) { var pageInfo = this.internal.getCurrentPageInfo(); + var getHorizontalCoordinateString = this.internal.getCoordinateString; + var getVerticalCoordinateString = this.internal.getVerticalCoordinateString; + pageInfo.pageContext.annotations.push({ - x: x, - y: y, - w: w, - h: h, + finalBounds: { + x: getHorizontalCoordinateString(x), + y: getVerticalCoordinateString(y), + w: getHorizontalCoordinateString(x + w), + h: getVerticalCoordinateString(y + h) + }, options: options, type: "link" }); diff --git a/test/reference/insertLinkAddPage.pdf b/test/reference/insertLinkAddPage.pdf new file mode 100644 index 000000000..523e3fd8b Binary files /dev/null and b/test/reference/insertLinkAddPage.pdf differ diff --git a/test/specs/annotations.spec.js b/test/specs/annotations.spec.js index f053df7c3..b13f52493 100644 --- a/test/specs/annotations.spec.js +++ b/test/specs/annotations.spec.js @@ -55,4 +55,21 @@ describe("Module: Annotations", () => { }); comparePdf(doc.output(), "freetext.pdf", "annotations"); }); + it("should draw a link on the text with link after add page", () => { + const doc = new jsPDF({ + unit: "px", + format: [200, 300], + floatPrecision: 2 + }); + + doc.textWithLink("Click me!", 10, 10, { + url: "https://parall.ax/", + }); + + doc.addPage("a4"); + + doc.text("New page with difference size", 10, 10); + + comparePdf(doc.output(), "insertLinkAddPage.pdf", "annotations"); + }); });