问题
How is it possible to fill PDF input fields with javascript ( if it is even possible ). In my case I want to create a javascript in which I can fill a HTML form, the data which the user put in the HTML form should be saved into the PDF Input Field.
Thanks in advance.
回答1:
I was looking on how to populate existing fields in a PDF with Node and after a while I found pdf-fill-form as a great option to do so.
And you can use it really easy
  // First get the Id of the value you need to populate in the pdf
  const pdfFillForm = require('pdf-fill-form');
  const fs = require('fs');
  let pdfFields = pdfFillForm.readSync('test/files/axapdf.pdf');
  console.log(pdfFields);
  var pdf = pdfFillForm.writeSync('pdf_to_fill.pdf',
    {'65536':'Set the value here'}, { "save": 'pdf' });
  fs.writeFileSync('filled_test_sync1.pdf', pdf);
    回答2:
you can use jpdf for the same, here is a fiddle demonstrating the same.
 var pdf = new jsPDF('p', 'mm', [297,210]);//page size
 var options = {
     pagesplit: true
    };
 pdf.addHTML($('#text_land')[0],options, function () {//data to print
 pdf.save('Test.pdf');
 });
study the fiddle, you must find what you are seeking for.
来源:https://stackoverflow.com/questions/34876459/fill-pdf-input-fields-with-javascript