textWithLink not working
I have read and understood the contribution guidelines. Configuration:
- used with Node v16.15.1, with TypeScript
Steps to reproduce the problem:
- Create new jsPdf doc
- Try to add textWithLink with provided string and link/pageNumber according to the API
- After further editing, call the save method.
const addContentListItemText = (
pdfDocument: jsPDF,
contentListItem: ContentListItem,
xOffset: number,
xIndent: number,
yOffset: number,
ySpacing: number,
pageWidth: number,
pageHeight: number,
totalNumberOfPages: number,
isSubitem = false,
) => {
const lineHorizontalPadding = 10;
const yOffsetHeightDiff = pageHeight - yOffset;
if (yOffsetHeightDiff <= 2 * ySpacing) {
pdfDocument.addPage().setPage(pdfDocument.getNumberOfPages());
yOffset = 30;
} else {
yOffset += ySpacing;
}
pdfDocument
.setFontSize(15)
.setFont(fontFamily, "normal")
.setTextColor("black")
.setFont(fontFamily, "normal")
.textWithLink(contentListItem.contentName, xOffset + (isSubitem ? xIndent : 0), yOffset, {pageNumber: totalNumberOfPages + contentListItem.index});
pdfDocument
.setLineDashPattern([1, 3], 0)
.line(
xOffset +
pdfDocument.getTextWidth(contentListItem.contentName) +
(isSubitem ? xIndent : 0) +
lineHorizontalPadding,
yOffset,
pageWidth - xOffset - lineHorizontalPadding,
yOffset,
);
pdfDocument.text(`${totalNumberOfPages + contentListItem.index}.`, pageWidth - xOffset, yOffset);
return yOffset;
};
Expected to add a hyperlink which leads to the given link/page number.
With a link (tried providing {link: "https://www,google.com} instead of "pageNumber") only pure text is added.
If using pageNumber, an error comes up when saving ("jsPDF PubSub Error Cannot read properties of undefined (reading 'objId') TypeError: Cannot read properties of undefined (reading 'objId')")
try to use link rectangle over hyperlink text (while this issue not fixed)
doc.link(x, y, w, h, {pageNumber: (pageNumTemp + 1)})
or
doc.link(x, y, w, h, {url: 'https://www.example.com/'});
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.