NodeJS和PDFkit:' margin' property给出"意外的标识符"错误?

时间:2016-10-27 04:18:30

标签: node.js pdf coffeescript pdfkit

我已成功获取输出pdf的代码,但是当我尝试使用' margin'来调整边距时使用以下代码

documentation中列出的属性
var pdf = require ('pdfkit');
var fs = require('fs');

var doc = new pdf(
{
    size: [288,144]

}
);

doc.pipe(fs.createWriteStream('run.pdf'));

doc.font('Times-Roman')
   .text('Hello different Times Roman!')

doc.addPage({
    size: [288,144]
    margin : 10
});

doc.end(); 

我收到此错误:

margin : 10
^^^^^^

SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

我错过了一些明显的东西吗?

1 个答案:

答案 0 :(得分:2)

为了确保任何未来的读者都能遇到这个特定的问题,这是一个JavaScript对象。列出JavaScript对象时,除最后一个实例外,每个属性后面都必须跟,

例如,这个:

doc.addPage({
    size: [288,144]
    margin : 10
});

成为这个:

doc.addPage({
    size: [288,144], 
    margin : 10
});