如何使用pdf-lib删除pdf文件中的图像

时间:2019-08-29 10:21:55

标签: pdflib

  

我想使用javascript中的pdf-lib删除pdf文件中的特定图像。

var PDFDocument = PDFLib.PDFDocument;
    const pdfBuffer = await fetch(pdf_url).then((res) => res.arrayBuffer())
    const pdfDoc =  await PDFDocument.load(pdfBuffer);
    const firstPage = pdfDoc.getPages()[0];
    const imageRef = firstPage
        .get<PDFDictionary>('Resources')
        .get<PDFDictionary>('XObject')
        .get<PDFIndirectReference>('CatRidingUnicorn');

    pdfDoc2.index.index.delete(imageRef);
    const pdfBytes = await pdfDoc.save();

0 个答案:

没有答案