0

I have successfully gotten my code to output a pdf, but when I attempt to adjust the margins using the 'margin' property listed in the documentation using the following code,

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(); 

I get this error:

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

Am I missing something obvious here?

user3574621
  • 3
  • 1
  • 3

1 Answers1

4

Just to ensure any future reader come here with this specific problem, this is a JavaScript Object. When listing JavaScript Objects, every property must be followed by a , except the last instance.

As an example, this:

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

becomes this:

doc.addPage({
    size: [288,144], 
    margin : 10
});
Dandy
  • 1,466
  • 16
  • 31
  • This is a little pedantic, but it's not JSON, it's a JavaScript Object. It would be JSON if it were encoded as a string (http://stackoverflow.com/questions/8294088/javascript-object-vs-json). But the same formatting and syntax applies, so the problem was still solved. +1 – caffeinated.tech Oct 27 '16 at 09:50