You must Sign In to post a response.
  • Category: Webservices

    Open PDF document using web api through Angular JS

    Hi

    I have to show Blob object as PDF in Angular JS

    Do we have any code to show PDF in Chrome using web api through angular JS code

    Thanks
    N.Muthu.
  • #769120
    $http({
    url : '/path/to/your/API',
    method : 'POST',
    params : {},
    headers : {
    'Content-type' : 'application/pdf',
    },
    responseType : 'arraybuffer'
    }).success(function(data, status, headers, config) {
    // TODO when WS success
    var file = new Blob([ data ], {
    type : 'application/csv'
    });
    //trick to download store a file having its URL
    var fileURL = URL.createObjectURL(file);
    var a = document.createElement('a');
    a.href = fileURL;
    a.target = '_blank';
    a.download = 'yourfilename.pdf';
    document.body.appendChild(a);
    a.click();
    }).error(function(data, status, headers, config) {
    //TODO when WS error
    });
    7:03 PM

    $scope.saveAsPDF = function() {
    var form = document.createElement("form");
    form.setAttribute("action", "some/path/to/the/file");
    form.setAttribute("method", "get");
    form.setAttribute("target", "_blank");

    var hiddenEle1 = document.createElement("input");
    hiddenEle1.setAttribute("type", "hidden");
    hiddenEle1.setAttribute("name", "some");
    hiddenEle1.setAttribute("value", value);

    form.append(hiddenEle1 );

    form.submit();

    }


    The above code is not working


  • Sign In to post your comments