2

I have an HTML form with several user input fields of type checkbox, text area and radio buttons that I need to download as a PDF file with the input values given by the user. I'm using jsPDF successfully to export the HTML div to a PDF but the input fields do not have any values in the PDF result. How do I export the entire form with the input values? Here is my jsPDF javascript for exporting to PDF:

self.onDownload = function (divId){
     var doc = new jsPDF();
     doc.fromHTML(document.getElementById(divId), 15, 15, {
          'width': 170
     });
     doc.save('sample-file.pdf');
}
1

2 Answers 2

2

I myself have been building functionality like you have described.

With regards to the issue you are experiencing, my current understanding is that most PDF generation libraries, like jsPDF, can't read/interpret the value attributes of input fields, which is why they aren't appearing in the PDF.

One way around this is to use a DOM to Image generator, then to save the image as a PDF. While it's not the most elegant of solutions, it does work and is the best solution I have found thus far. I've been using the html2canvas library for creating the image, and jsPDF for creating the pdf.

There is a tutorial here, that takes you through setting up a basic html to pdf function, using html2canvas and jsPDF.

Sign up to request clarification or add additional context in comments.

Comments

0

This seem to be false, albeit being a year later.

By using

doc.text(20, 20, document.getElementById("YourDiv/Paragraph").innerHTML);

or

document.getElementById("InputField").value

I could use elements within the html file properly.


Leaving this here to avoid confusion in the future. For variables as asked here: Variables in jsPDF

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.