Export HTML form to PDF with input field initialized by js does not appear in Pdf document

2

I have an HTML form where each input tag has its empty value attribute. This value attribute must be filled in randomly by a javascript code. So far so good. The problem is that when I use the plugin (jspdf) to submit this form to a PDF output, the value field of the form does not appear in the output of the pdf document. With this the document is exported only with the label, without its content.

The name drawn appears on the screen but unfortunately it is not set in the value property of the input tag and therefore does not appear in the pdf document when it is exported.

My question, is there any way I can enforce the value property of the input tag by the javascript code?

Asyoucanseeintheprint,thenamewasgenerated"Monge", but when inspecting the element its value attribute is empty. When I order to download via pdf the document is as below:

    
asked by anonymous 11.03.2016 / 15:11

2 answers

-1

Using jsPDF- link

var pdf = new jsPDF('p','pt','a4');

pdf.addHTML(document.body,function() {
    //Funcionou !
});
    
11.03.2016 / 15:41
-1

To generate PDF the best tool is jsPDF. With it you can print the section of your HTML you want. There are several non-customizable plugins including jsPDF & autoTable that allows you to print a complete table or jspdf & html2canvas that allows you to take a photo of a page or section to print.

In this case, the use of jspdf & html2canvas.

var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

$('#cmd').click(function () {   
    doc.fromHTML($('#content').html(), 15, 15, {
        'width': 170,
            'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js"></script>
<div id="content">
    <h3>Filter Section</h3>
    <p>Test will be print where</p>
</div>
<div id="editor"></div>
<button id="cmd">Generate PDF</button>

You can also see link several examples.

    
06.04.2018 / 12:09