jsPDF - include other pdf

后端 未结 2 1422
广开言路
广开言路 2021-01-14 08:01

I\'m trying to solve such problem with jsPDF:

I have PDF file, which is stored on server. I\'m generating another pdf with jsPDF and trying to append to already exi

2条回答
  •  北海茫月
    2021-01-14 08:41

    jsPDF can't do this, but pdf-lib can. You can combine the two, or just use pdf-lib on its own. To load an existing pdf in pdf-lib, just do this:

    async function loadPdf(){
      const response = await fetch('existing.pdf');
      const buffer = await response.arrayBuffer();
      const existingPdfDocBytes = new Uint8Array(buffer);
      const pdfDoc = PDFLib.PDFDocumentFactory.load(existingPdfDocBytes);
      return pdfDoc;
    }
    

提交回复
热议问题