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

Asked

Viewed 1,071 times

2

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

I’ve been doing some research and only find information in PHP, where I have no knowledge about it.

someone could help me to intender how it works HTML/JS?

  • No PHP? Pure Javascript or with Jquery?

  • Isn’t it enough to print to PDF? Can you explain what you need to do to understand the framing.

  • with Jquery can be yes, as I said PHP I don’t know anything but if I had something well explained I could try

  • So Sergio, I can’t do a print because the screen is locked in the HTML test, this log would have to be generated in the background as soon as I reset such a test

  • I believe that with JS/jQuery it is impossible to save something to the server, because they work on the client side. If this were possible, it would be a serious security breach. It is necessary to use a server script such as PHP.

1 answer

2


If it is in PDF, you can use the Jspdf with the 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');
            }
        })

Browser other questions tagged

You are not signed in. Login or sign up in order to post.