0

I try to make a pdf file in my laravel program then download it, but the problem is the file can not be downloaded. This is my code:

Ajax:

$("#get_laporan_bap").click(function(){
    //alert("masuk");
    var atas_nama       = $("#atas_nama").val();
    var token           = $("#token").val();
    alert(atas_nama);
    $.ajax({
        type: "post",
        data: "atas_nama=" + atas_nama + "&_token=" + token,
        url: "<?php echo url('/get_laporan_tolsis') ?>",
        success:function(data){
            console.log(data);
        }
    });
});

Controller:

public function get_laporan_tolsis(Request $req){
    $atas_nama  = $req->atas_nama;
    $tanggal    = \Carbon\Carbon::now()->toDateString() ;
    $nama_file  = "Laporan Tolsis[".$tanggal."].pdf";

    $data = DB::table('bap_tolsis')->select('*')->whereDate('tanggal_input', $tanggal)->where('status',"=",'belum')->get();

    $pdf    = PDF::loadView('laporan_tolsis',['data'=>$data]);
    return response($pdf->download($nama_file, array("Attachment" => false)));
}

I really have no idea to solve it. Help me guys, thanks.

  • Downloading PDF file via ajax isn't a good option please check @ https://stackoverflow.com/questions/34586671/download-pdf-file-using-jquery-ajax/34587987 Why don't you use https://github.com/barryvdh/laravel-dompdf – Iftikhar uddin Oct 14 '18 at 12:00
  • Does it mean that i really can't do it with ajax @Iftikharuddin?, Just for your information that I can download the pdf by using idm, but without idm I can't. – Muhammad Haryadi Futra Oct 14 '18 at 12:30
  • nothing is impossible keep digging but up to now I haven't found any solution yet. – Iftikhar uddin Oct 14 '18 at 13:57
  • hi, did you solved the problem. same with me i can't download the pdf file – SoulAiker Mar 08 '20 at 04:09

0 Answers0