Method 1:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PdfController extends Controller
{
public function index()
{
return view('pdf.index');
}
public function create()
{
$pdf = public_path('pdf/test.pdf');
return response()->download($pdf);
}
}
<template>
<div id="app">
<button @click="onClick()">DownLoad</button>
</div>
</template>
<script>
import axios from 'axios'
export default {
methods: {
onClick() {
axios({
url: 'api/downloadPdf',
method: 'GET',
responseType: 'arraybuffer',
}).then((response) => {
let blob = new Blob([response.data], {
type: 'application/pdf'
})
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = 'test.pdf'
link.click()
});
}
}
}
</script>
No comments:
Post a Comment