2014-09-22 43 views
0

我已經安裝了meteor add jaredmartin:pdfkit,但文檔看起來不正確。我收到第一行的錯誤PDFDocument = require'pdfkit'並且無法通過此操作?是否有流星pdfkit手冊或我在流星0.9上做錯了什麼?如何在流星上使用pdfkit

+0

使用pdfmake與流星,pdfmake是pdfkit上的包裝lib – 2016-11-29 04:50:19

回答

0

我也有麻煩。我發現了一箇舊的流星包,它沒有這條線,但我還沒有使它工作。

 var doc = new PDFDocument({size: 'A4', margin: 50}); 
 
     var imageBase64 = Meteor.users.findOne(this.userId).profile.picture; 
 
     var imageBuffer2 = new Buffer(imageBase64.replace('data:image/png;base64,','') || '', 'base64'); 
 
     doc.image(imageBuffer2, 10, 10, {height: 75}); 
 
     doc.fontSize(12); 
 
     doc.text('PDFKit is simple', 10, 30, {align: 'center', width: 200}); 
 
     // Save it on myApp/public/pdf folder (or any place) with the Fibered sync methode: 
 
     doc.writeSync(process.env.PWD + '/public/pdf/PDFKitExample.pdf');

+0

你能推薦任何其他的替代軟件包嗎? – james 2014-10-15 18:13:44

1

哇,我剛剛看到這個在這裏,我很抱歉這是這麼久,你用我的包有問題。事實是,我當時就是這麼做的,pascual並沒有更新他的原始包裝以與新的流星包裝系統合作,所以我讓我作爲一個權宜之計。從那時起,他已經更新了他的軟件包,所以我建議你使用他的軟件包pascoual:pdfkit

0

在流星1.1.0.2中,即時通訊使用路由頁面來構建PDF並下載它。

(考慮:包乘:鐵路由器進步和pascoual:pdfkit)

Router.route('/buildPDF/:_param1', function() { 

    var param1 = this.params._param1; 
    if (!param1) return; 

    var doc = new PDFDocument({ 
    size: 'A4', 
    margins: { 
     top: 50, 
     bottom: 0, 
     left: 50, 
     right: 50, 
    } 
    }); 

    doc.image(process.env.PWD + '/public/img/sample1.jpg', 0, 30, { 
    width: 598 
    }); 

    doc.rect(0, 370, 598, 210) 
    .fill('#22829f', 'even-odd'); 

    doc.fontSize(25).fillColor('white'); 
    doc.text('some text', 50, 390, { 
    align: 'center', 
    width: 500 
    }); 

... 

    this.response.writeHead(200, { 
    'Content-type': 'application/pdf', 
    'Content-Disposition': 'attachment; filename=sometitle.pdf' 
    }); 
    this.response.end(doc.outputSync()); 
}, { 
    where: 'server' 
}); 

所有作品prefecly,在鍍鉻的PDF自動下載,當我安裝在試驗流星服務器除外,我只是在空白頁面收到消息錯誤

服務器錯誤。

使用流星日誌myapp.meteor.com我得到這個:

W20150615-16:52:09.513(-3)? (STDERR) Error: ENOENT, no such file or directory '/Users/EdU/Documents/Develope/git-repos/TyTimg/layers/sample1.jpg' 
W20150615-16:52:09.515(-3)? (STDERR)  at Object.fs.openSync (fs.js:439:18) 
W20150615-16:52:09.515(-3)? (STDERR)  at Object.fs.readFileSync (fs.js:290:15) 
W20150615-16:52:09.515(-3)? (STDERR)  at Function.PDFImage.open (/Users/EdU/.meteor/packages/pascoual_pdfkit/.1.0.5.7067nv++os+web.browser+web.cordova/npm/node_modules/pdfkit/js/image.js:27:28) 
W20150615-16:52:09.515(-3)? (STDERR)  at PDFDocument.module.exports.image (/Users/EdU/.meteor/packages/pascoual_pdfkit/.1.0.5.7067nv++os+web.browser+web.cordova/npm/node_modules/pdfkit/js/mixins/images.js:30:26) 

變量process.env.PWD寬鬆的背景下進入流星測試服務器。我試圖解決這個問題。我希望能幫助你。

+0

已解決: 我使用過的代碼 'var basePath = process.cwd()+'/../web.browser/app/'; doc.image(basePath +'img/layers/sample1.jpg',0,30);' 並且完美的作品 – EdU 2015-06-17 17:09:40