jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

textWithLink not working

Open MilosLukicBM opened this issue 3 years ago • 1 comments

I have read and understood the contribution guidelines. Configuration:

  • used with Node v16.15.1, with TypeScript

Steps to reproduce the problem:

  1. Create new jsPdf doc
  2. Try to add textWithLink with provided string and link/pageNumber according to the API
  3. 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')")

MilosLukicBM avatar Aug 09 '22 09:08 MilosLukicBM

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/'});

glebov21 avatar Sep 19 '22 15:09 glebov21

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.

github-actions[bot] avatar Dec 19 '22 01:12 github-actions[bot]