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

Trouble getting the pdf to display #180

Closed SensationSama closed 7 years ago

SensationSama commented 7 years ago

Objective

  1. User selects a .pdf file from a list
  2. 'Preview File' modal loads with pdf

Using the library I was receiving a null context error due to the javascript running before the modal loads. (The Bootstrap devs don't want manipulation to happen from the controller, so there's no event catch for the modal being loaded or ready)

As a lame solution I made it so that the user can press a preview button on the modal. This calls a function injectPdf which adds the rest of the neccessary code to display the PDF. Now it's a simple implementation, but still not working.

Modal Controller

this.pdfUrl = "http://www.jeremyzerr.com/sites/default/files/Getting-Started-with-AngularJS.pdf";
injectPdf() {
 var html = '<ng-pdf canvasid="pdf-canvas" template-url="pdf.html" debug="true"></ng-pdf>';
 document.getElementById("elemId").innerHTML = html;
}

Modal HTML

<div ng-if="modal.file.extension == 'pdf'">
  <button ng-click="modal.injectPdf()">Preview</button>
  <div id="elemId" style="border-radius: 4px; border-color: ghostwhite; border-style: solid; border-width: 3px;">
  </div>
</div>

pdf.html <canvas id="pdf-canvas"></canvas>

Html gets injected so no clue what is lacking here. Currently it doesn't display and I'm not getting any console errors. Thanks.

dennybiasiolli commented 7 years ago

Hi @SensationSama, can you provide a full JSFiddle (ore something else) with your code? Thanks!

SensationSama commented 7 years ago

@dennybiasiolli I'm not on the current version of angular but it's approximately like this.

Script imports at the top are set up for a local directory, so they're definitely wrong via fiddle.

I also nested the <canvas> content in the inject in the example. (I don't see anywhere to incorporate an additional html file)

dennybiasiolli commented 7 years ago

@SensationSama I doubt that your example is an angular app. Without a real example I can not tell you where the problem is. Sorry

simobasso commented 7 years ago

@SensationSama maybe you have to compile your injection? For the next time remember that deleted comments are sent via email anyway :).

SensationSama commented 7 years ago

@dennybiasiolli @simobasso I ended up using https://pdfobject.com/

Thanks anyway fellas