Fill PDF Input fields with Javascript

孤者浪人 提交于 2020-08-26 07:41:05

问题


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

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