Skip to content

Commit

Permalink
Fix broken links after addPage with different page size (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceloZapatta authored Oct 7, 2020
1 parent fe706dc commit c964480
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/modules/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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"
});
Expand Down
Binary file added test/reference/insertLinkAddPage.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions test/specs/annotations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit c964480

Please sign in to comment.