首页 > 解决方案 > 在 pdf-lib 中设置 Pdf 图像注释的链接

问题描述

我有一个 Pdf 文件,我正在尝试在图像上添加图像和一个带有链接的矩形...

使用https://www.npmjs.com/package/pdf-lib

 const pdfDoc = await PDFDocument.load(await pdf.getData());

    const pages = pdfDoc.getPages()

    const page = pages[index]

    const pngImage = await pdfDoc.embedPng(pngImageBytes)
    
    const pngDims = pngImage.scale(0.5)
    
    // Draw the PNG image near the lower right corner of the JPG image

    //   x: page.getWidth() / 2 - pngDims.width / 2 + 75,
    //   y: page.getHeight() / 2 - pngDims.height,
    page.drawImage(pngImage, {
        x:coordinations.x - pngDims.width / 2,
        y:coordinations.y - pngDims.height / 2,
        width: pngDims.width,
        height: pngDims.height,
    })

    const pdfBytes = await pdfDoc.save()

图像已创建,但我找不到通过图像上的链接创建矩形的方法

所以人们可以点击图片并打开链接....

标签: javascriptreactjspdf

解决方案


推荐阅读