问题
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 existed pdf file (as I mentioned above) as a another page.
I googled about it, but can't find any help. Also I found this question on stackoverflow, but it is different scenario - Append Existing Pdf to Jspdf
How can I make this to work? Or is any other plugin or something else to make this?
回答1:
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.
回答2:
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;
}
来源:https://stackoverflow.com/questions/51994326/jspdf-include-other-pdf