PDF being generated with blank sheets

Asked

Viewed 216 times

0

I have an API in Laravel that has an end-point (POST method) to generate PDF (Dompdf) with the following method:

public function generatePDF()
{
    return \PDF::loadView('mailing::templates.pdf.model')->download('nome-arquivo-pdf-gerado.pdf');
}

I did the test by Insomnia and the PDF is generated normally, but in my front end (Vuejs) the whole document is blank without any information.

downloadPDF() {
      download(this.compose)
        .then((response) => {
          this.saving = false;

          const url = window.URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement('a');
          link.href = url;
          link.setAttribute('download', 'file.pdf');
          document.body.appendChild(link);
          link.click();
        })
        .catch((error) => {
          console.error(error);
        });
    },

What could be causing this problem?

1 answer

1


Your method for downloading the PDF may not be right. I advise you to specify the type of answer for blob, as an example:

const pdf = {
  download: url =>
    http({
      method: 'get',
      responseType: 'blob',
      url
    })
}

Browser other questions tagged

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