1

Hello I'm requesting a pdf from a webservice and want to show pdf when the request is finished and I've generated an ObjectUrl. My problem is, that the ng-src in "embed" or the ng-data-attr in "object" is not compiled and the browser is downloading url/{{pdfData}}

Here's my DOM:

 <div ng-if="pdfData != ''">

    <embed ng-src="{{pdfData}}" style="width:200px;height:200px;" type="application/pdf"></embed>

    <!--<object ng-bind="pdfData" data="{{pdfData}}" type="application/pdf" width="100%" height="800px">-->
    <br>Objekt:
   <object ng-attr-data="{{pdfData}}" type="application/pdf" width="100%" height="800px">

My JS Code:

$http.post('url', { }).
   then(function(response) {
      var byteCharacters = atob(response.data.trim())
      var byteNumbers = new Array(byteCharacters.length);
      for (var i = 0; i < byteCharacters.length; i++) {
         byteNumbers[i] = byteCharacters.charCodeAt(i);
      }
      var byteArray = new Uint8Array(byteNumbers);
      var blob = new Blob([byteArray], {type: 'application/pdf'});

      var blobUrl = URL.createObjectURL(blob);

      $scope.pdfData = $sce.trustAsResourceUrl(blobUrl);

      }, 
      function errorCallback(response) {
           console.log(response);
      });

When I'm running the above code it works fine on Google Chrome, but not in IE/Firefox.

I've also tried an own directive like it is described here: angularjs expression in html <object> tag

But then I have the problem, when I'm creating a new src-url for another PDF, the new pdf I assign to $scope.pdfData is not loaded in the embed or object control.

Thanks for your help

artgb
  • 3,177
  • 6
  • 19
  • 36
user1829716
  • 307
  • 1
  • 9
  • 20
  • Would you like to make snippet or jsfiddle for clarify? – artgb Aug 24 '17 at 15:59
  • Hello, I prepared a plunkr. Unfortunatly the request for loading base 64 is not working (but I have no problem with it in my environment). But maybe you see whats going wrong. Thanks for your help! Plunkr: https://plnkr.co/edit/a5QxhESRmBPECexh1jOc?p=streamer – user1829716 Aug 25 '17 at 11:01

0 Answers0