I have a web application that is currently getting a base64 representation of a PDF from the server. I'm able to use Mozilla's pdf.js to display this on a <canvas>
and toggle through the pages with a dropdown.
According to everything I've been able to find and Can Mozilla's pdf.js modify PDFs?, it's not possible to edit the PDF with pdf.js.
I've found jsPDF and while I'm able to take the canvas and do a .toDataURL()
with it for each page and build a new PDF document with it, but there are two issues:
- The newly generated PDF will just be a series of images on each page, so any text in the original PDF will just be an image after I'm done with it.
- I generate a new PDF with jsPDF and then send the base64 of it back to pdf.js to display it on the canvas. Something happens between these steps where the images of the pages get scaled incorrectly, so each page takes up about 3/4 of the canvas after each new PDF change. I've been unable to get it to retain the same size/scale.
jsPDF doesn't look like it has a way to load an existing PDF, it only creates new ones. pdfmake and PDFKit also look like they only create new PDF files.
So my question:
Is there anything that will allow for both viewing a pdf (from base64) and for making changes to it?
Ideally I'd watch for changes to the canvas, then draw that change onto the pdf page. When done, export that to a base64 string to send back to the server.