How to get AngularJS BLOB to Download PDF?

后端 未结 5 2031
甜味超标
甜味超标 2021-01-12 08:54

Hello everyone I am really new to developing with AngularJS and I am trying to figure out how to use BLOB to download a PDF locally to a machine. I already got it to work wi

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 09:42

    In you controller PHP

       return $pdf->stream();
    

    In you controller AngularJS

    $http.post('generate', {
        dateStart:  $scope.ds,
        dateEnd:    $scope.de
    }, 
    {
      responseType: 'arraybuffer'
    }).then(function success(response) {
    
      var blob = new Blob([response.data], { type: "application/pdf"});
      saveAs(blob, "filename.pdf");
    
    }, function error(error) {
        $scope.recordErrors(error);
    });
    

提交回复
热议问题