jsPDF - include other pdf

牧云@^-^@ 提交于 2019-12-06 08:06:50

Unforfortunately, with jsPDF today (2018) it is not supported.

Alternative solution

But you could edit server side with free PHP library like FPDI. With FPDI it is even possible to edit PDF documents, extract some pages and to add them to new PDF documents. How to do it see here.

You could send to your server a request using AJAX and the server do it and gives you a new PDF back.

oligofren

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!