How to save data from an HTML page to a file via Javascript?

2

I do not know anything about this, and an application came up here in the service where I need to get the data from a HTML page, and generate a TXT , or a PDF >, the save will be on the machine itself, because the server is local.

I've been researching a little and I only find information in PHP, where I am not aware of it.

Could anyone help me understand how this manipulation works in HTML/JS ?

    
asked by anonymous 10.10.2017 / 20:48

1 answer

2

If it's in PDF, you can use JSPdf with HTML2Canvas , a simple example of its use.

<div id="div">CONTEUDO</div> 
<button id="download">GERAR PDF</button>

let html = document.getElementById('div')
html2canvas(html, {
            onrendered: function(canvas) {         
                let retorno = canvas.toDataURL(
                    'image/png');              
                let doc = new jsPDF('p', 'mm');
                doc.addImage(retorno, 'PNG', 10, 10);
                doc.save('arquivo.pdf');
            }
        })
    
10.10.2017 / 21:07