Fidha Nasher Fidha Nasher - 1 year ago 87
AngularJS Question

Download PDF file from Sever through Angularjs Get Method

I am created a lavavel DomPdf using below code segment

$pdf = App::make('dompdf.wrapper');
return $pdf->download('sample.pdf');

It perfectly working with the route and getting PDF.

I need to download it using AngularJs GET Method as given below

var file = new Blob([ data ], {
type : 'application/csv'
//trick to download store a file having its URL
var fileURL = URL.createObjectURL(data);
var a = document.createElement('a');
a.href = fileURL; = '_blank'; = 'yourfilename.pdf';

It not working. I need to Download PDF using AngularJs GET Method

Answer Source

use POST Method rather than GET Method and use the following AngularJs Code

var req = {
        method: 'POST',
        url: 'api/getBulkHallTicket',
        data: {exam_centres_id:$scope.option1,mode:$scope.mode}

        .success(function(data, status, headers){
            var arr = data;
            var byteArray = new Uint8Array(arr);
            var a = window.document.createElement('a');

            a.href = window.URL.createObjectURL(
                new Blob([byteArray], { type: 'application/octet-stream' })
   ='hallticket.pdf' ;//headers('filename');

            // Append anchor to body.

            // Remove anchor from body

I hope this will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download