Skip to content

Instantly share code, notes, and snippets.

@clairtonluz
Created June 11, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clairtonluz/a16346341162c5272294cb6ed55c4b8e to your computer and use it in GitHub Desktop.
Save clairtonluz/a16346341162c5272294cb6ed55c4b8e to your computer and use it in GitHub Desktop.
// faz uma requisiço do tipo post e o response dessa requisição é o PDF
this.fetch(`blog.clairtonluz.com.br/gerarPDF`, {method: 'POST'})
.then(response => response.blob())
.then(file => {
// Criar uma url local para o arquivo baixado.
const url = window.URL.createObjectURL(blob);
// Criar um link
const a = document.createElement('a');
// define o href do link para a url criada
a.href = url;
// define o nome para o arquivo que vai ser baixado
a.download = 'nomeDoArquivo.pdf';
// inicia o download no navegador
a.click();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment