2017-03-14 68 views
1

我正在使用wkhtmltoimage。它適用於例如http://stackoverflow.com如何呈現AngularJs網站的圖像?

但是,當我嘗試使用AngularJs在任何網站上運行(如https://material.angularjs.org/latest/):

wkhtmltoimage.exe --no-stop-slow-scripts --javascript-delay 5000 --enable-javascript --debug-javascript https://material.angularjs.org/latest/ C:\\dev\\temp\\0c8fca2c-0990-40c4-8672-12fc71ec6cf6.png 

一個得到一個錯誤的JS錯誤(感謝:--debug-javascript標誌)

Loading page (1/2) 
Warning: undefined:0 Error: [$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=ng&p1='undefined'%20is%20not%20an%20object 
Rendering (2/2) 

的結果圖像只是一個很小的白色條紋。

如何仁

+0

當您在瀏覽器中打開它時,您的頁面是否正常呈現,或者您還在那裏出現錯誤? - 哦,你說任何angularjs頁面 –

+0

@ Gonzalo.-當然。該頁面包含在我正在使用的附加命令中(Angular Material的主頁)。 – gisek

回答

2

看來,wkhtmltopdf不Function.prototype.bind發揮很好(在角> = 1.5使用),所以你需要提供一個「填充工具」,以它的工作原理。

Function.prototype.bind = function(oThis) { 
    if (typeof this !== 'function') { 
     throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); 
    } 

    var aArgs = Array.prototype.slice.call(arguments, 1), 
     fToBind = this, 
     fNOP = function() {}, 
     fBound = function() { 
      return fToBind.apply(this instanceof fNOP 
       ? this 
       : oThis, 
       aArgs.concat(Array.prototype.slice.call(arguments))); 
     }; 

    if (this.prototype) { 
     fNOP.prototype = this.prototype; 
    } 

    fBound.prototype = new fNOP(); 

    return fBound; 
}; 
+0

我需要在何處提及此代碼?我嘗試過,但仍然不能正常工作 – Mahajan344

+0

您需要將此添加到您的應用中包含的任何* .js文件中。 – vitozev