vendredi 13 août 2021

Pdf not opening properly generated with dom pdf

I'm generating pdf using dom pdf.

Code :

$dompdf = new Dompdf();
$pdfData=Data::where('id',auth()->user()->id)->first();
$html = view('admin/view-data/',['pdfData'=>$pdfData])->render();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$fileName = 'filenaname.pdf';
Storage::put('public/pdf'.$fileName, $dompdf->output());

pdf is being generated in the storage/app/public/pdf/ folder

i'm downloading it using vue.js :

Link:

<a   href="#" class="btn btn-xs btn-success" title="Downaload" @click="downloadIt('/storage/'+user.user_id)"><i class="fa fa-file-pdf" aria-hidden="true"></i></a>

Method:

 downloadIt(url) 
{
 var str = url.split("/"); 
 var filename = str[str.length - 1]; 
    axios.get(url, {responseType: 'blob'})
  .then((response) => {
        const url = window.URL.createObjectURL(new Blob([response.data]));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', filename);
        document.body.appendChild(link);
        link.click();
        })
},

but when i downloaded it i'm getting this message

enter image description here

but when i open it directly from storage folder it is opening. Any solution, Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3iFbYie
via IFTTT

Aucun commentaire:

Enregistrer un commentaire