0

I would like to use this to show PDF in my SPA.

I tried to build a single example but it didn't work. Look this Plunker

http://plnkr.co/edit/nZAjYr?p=preview

In this example my pdf is in http://example.com/file.pdf

I really don't know where is the error, maybe it be in my controler:

angular.module('app', ['pdfjsViewer']);

angular.module('app').controller('AppCtrl', function ($scope, $http, $timeout) {
    var url = 'http://example.com/file.pdf';

    $scope.pdf = {
        src: url,  // get pdf source from a URL that points to a pdf
        data: null // get pdf source from raw data of a pdf
    };

    getPdfAsArrayBuffer(url).then(function (response) {
        $scope.pdf.data = new Uint8Array(response.data);
    }, function (err) {
        console.log('failed to get pdf as binary:', err);
    });

    function getPdfAsArrayBuffer (url) {
        return $http.get(url, {
            responseType: 'arraybuffer',
            headers: {
                'foo': 'bar'
            }
        });
    }
});

Can anyone helpe me please?

1 Answer 1

1

Your controller should look something like this:

angular.module('app').controller('AppCtrl', function ($scope, $sce, $http, $timeout) {
    var url = 'http://example.com/file.pdf';
    PDFJS.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js'

    $scope.pdf = {
        src: $sce.trustAsResourceUrl(url),  // get pdf source from a URL that points to a pdf
        data: null // get pdf source from raw data of a pdf
    }; 
});

Remove the unnecessary code and check the console for more details.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.