title: Edit *existing* PDF in a browser
body: <p>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 <code>&lt;canvas&gt;</code> and toggle through the pages with a dropdown.</p>
  
  <p>According to everything I've been able to find and <a href="https://stackoverflow.com/questions/12085597/can-mozillas-pdf-js-modify-pdfs">Can Mozilla&#39;s pdf.js modify PDFs?</a>, it's not possible to edit the PDF with pdf.js.</p>
  
  <p>I've found <a href="https://github.com/MrRio/jsPDF" rel="noreferrer">jsPDF</a> and while I'm able to take the canvas and do a <code>.toDataURL()</code> with it for each page and build a new PDF document with it, but there are two issues:</p>
  
  <ol>
  <li>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.</li>
  <li>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.</li>
  </ol>
  
  <p>jsPDF doesn't look like it has a way to load an existing PDF, it only creates new ones. <a href="https://github.com/bpampuch/pdfmake" rel="noreferrer">pdfmake</a> and <a href="https://github.com/devongovett/pdfkit" rel="noreferrer">PDFKit</a> also look like they only create new PDF files.</p>
  
  <hr>
  
  <p>So my question:</p>
  
  <p>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.</p>