How to Force Download mpdf Files Using Ajax

Asked

Viewed 375 times

2

I am trying to download pdf files using the library mpdf.

Calling the php page in the browser it works normally.

Example:

require_once 'mpdf/mpdf.php';

$mpdf = new mPDF();

$boleto = '<h3>Boleto</h3>';

$mpdf->WriteHTML($boleto);

$mpdf->Output('teste.pdf',"D");

Now if I try to call it an html page using ajax its return looks like this:

inserir a descrição da imagem aqui

As I call Ajax:

var salvarBoleto = function(parcelas) {
  $.ajax({
    url: boletoUrl,
    data: {
      "acao": "salvarBoleto",
      "parcelas": parcelas
    },
    dataType: 'json',
    type: 'POST',
    success: function(data) {

    },
    error: function(data) {
      console.warn("mostrar msg de erro");
    }
  });
};

Normally I call a new tab to issue the pdf, but in this case I would like to do it on the ajax page.

  • You can post the JS snippet that calls the ajax?

  • @Laerte ready :)

  • @Gabrielrodrigues, remember you solved this ?

  • @Wagnerson if I remember well I had to open the file in an iframe to download on the same page, then I created an invisible iframe and acted his src.

No answers

Browser other questions tagged

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