sayanee / angularjs-pdf

:page_facing_up: An AngularJS directive <ng-pdf> to display PDF files with PDFJS
http://sayan.ee/angularjs-pdf/
MIT License
494 stars 248 forks source link

stream must have data on second load of PDF #181

Closed TrueGeek closed 7 years ago

TrueGeek commented 7 years ago

I'm using angularjs-pdf in an Ionic mobile app. It works wonderfully (thank you!) the first time I load a PDF. However, the second time the onError event fires with the message:

stream must have data

I get this even when reloading the save PDF twice in a row. Has anyone else seen this?

dennybiasiolli commented 7 years ago

Hi @TrueGeek, thanks for opening this issue :) Can you please provide a working example app so we can analyse the issue? Thanks!

TrueGeek commented 7 years ago

It turns out this issue was caused by the PDF not being written in time before the viewer started up. I'm not sure why it always worked the first time and not the second but I solved it by switching to a file writer that returned a promise so I could wait for the PDF to be written to disk before setting pdfURL to scope.

Thanks!

dennybiasiolli commented 7 years ago

Thanks for the feedback @TrueGeek ! :)