Skip to content
Advertisement

Render PDF using PDF.JS and AngularJS from byte array

I’ve been following the following links to try to render a byte stream returned from an API to a PDF in browser using PDF.JS:

Here is the JavaScript used to run render. Note: stream is a byte array returned from an API.

JavaScript

Here is $scope.renderPDF:

JavaScript

Here is the HTML in my template page:

JavaScript

When the code runs

JavaScript

I get a 404 Not Found error on worker.js, which makes sense because I’m following these examples and disabling worker so I shouldn’t need it. Does anyone have any advice or an easy way around this that I can render a pdf in browser from a byte stream?

Advertisement

Answer

You still need pdf.worker.js even if you have disabled it. Disabling it means that PDFJS will use faked workers for which it is also using the worker library. Just set it in the following way:

JavaScript
Advertisement