Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links break on addPage with different size #2943

Merged
merged 6 commits into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/modules/annotations.js
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
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");
});
});