2017-09-27 14 views
0

と連携作り、私はので、私はthisを試してみましたが、私はwebpackを使用していることから、webpackは私に、このエラーを与えた私のAngular 4アプリでpdfMakeを使用したい:pdfMakeは角4とのWebPACK

Could not find a declaration file for module 'pdfmake/build/pdfmake' 

をので、私は追加

:私の​​リストにスクリプトが

import 'pdfmake/build/pdfmake'; 
import 'pdfmake/build/vfs_fonts'; 

は私ProvidePlugin次のように変更しました

new webpack.ProvidePlugin({ 
     $: 'jquery', 
     jQuery: 'jquery', 
     'window.jQuery': 'jquery', 
     Popper: ['popper.js', 'default'], 
     pdfMake: 'pdfmake' 
    }), 

と私はこれが私のReferenceError: pdfFonts is not definedエラーを与えたが、私は、コンストラクタと宣言の最初の行をコメントアウトした場合、私はこのエラーを取得するpdfMake

//imports 
declare var pdfMake: any; 
declare var pdfFonts: any; 

@Component.... 
export class MyComponent { 
    constructor() { 
     pdfMake.vfs = pdfFonts.pdfMake.vfs; 
     var dd = { content: 'your pdf dataaaaaaaa' }; 
     pdfMake.createPdf(dd).download(); 
    } 

} 

使用したいコンポーネントにこれをしませんでした:

ERROR Error: File 'Roboto-Regular.ttf' not found in virtual file system 

これはエラーpdfMakeです。

私はそれらを使用できるようにvfs_fontsファイルからフォントを宣言する方法が私の質問ですか?

答えて

0

私はこのようになりますPrinterServiceを作ることになった:

あなたが出て入力する必要はありませんので、
@Injectable() 
export class PrinterService { 
    private readonly pdfFonts: any; 
    pdfMake: any; 

    constructor() { 
     this.pdfMake = require('pdfmake/build/pdfmake.js'); 
     this.pdfFonts = require('pdfmake/build/vfs_fonts.js'); 
     this.pdfMake.vfs = this.pdfFonts.pdfMake.vfs; 
    } 
} 

私は事前に定義されたヘッダーとフッター、ページ番号などで事前に定義されたオブジェクトを返す関数を持っていますドキュメントの定義はどこでも必要です。