diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-06-02 18:22:07 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-06-02 18:22:07 +0200 |
commit | 0ad0403d4112ba16886724d513d1a18e5f56d634 (patch) | |
tree | dbd53c1cf5e849c48fe04d47419c3bfddf824c41 | |
parent | 718692de3b4725caa41a7c2371acf634d149e5f7 (diff) | |
parent | 2515c1dd73911e238b6aa1a513fcfcf5f91e3082 (diff) | |
download | gitbook-0ad0403d4112ba16886724d513d1a18e5f56d634.zip gitbook-0ad0403d4112ba16886724d513d1a18e5f56d634.tar.gz gitbook-0ad0403d4112ba16886724d513d1a18e5f56d634.tar.bz2 |
Merge pull request #283 from GitbookIO/feature/pdfoptions
Add more options for PDF
-rw-r--r-- | README.md | 23 | ||||
-rwxr-xr-x | bin/gitbook.js | 11 | ||||
-rw-r--r-- | lib/generate/ebook/index.js | 35 |
3 files changed, 44 insertions, 25 deletions
@@ -98,6 +98,29 @@ Here are the options that can be stored in this file: "facebook": null, "twitter": null } + }, + + + // Options for PDF generation + "pdf": { + // Add toc at the end of the file + "toc": true, + + // Font size for the fiel content + "fontSize": 12, + + // Paper size for the pdf + // Choices are [u’a0’, u’a1’, u’a2’, u’a3’, u’a4’, u’a5’, u’a6’, u’b0’, u’b1’, u’b2’, u’b3’, u’b4’, u’b5’, u’b6’, u’legal’, u’letter’] + "paperSize": "a4", + + // Margin (in pts) + // Note: 72 pts equals 1 inch + "margin": { + "right": 62, + "left": 62, + "top": 36, + "bottom": 36 + } } } ``` diff --git a/bin/gitbook.js b/bin/gitbook.js index c2c2e31..b868925 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -80,17 +80,6 @@ build.command(prog.command('serve [source_dir]')) generate(); }); -build.commandEbook(prog.command('ebook [source_dir]')) -.description('Build a gitbook as a eBook (format detected according to the extension)') -.action(function(dir, options) { - var ext = options.output ? path.extname(options.output) : "epub"; - - build.file(dir, _.extend(options, { - extension: ext, - format: "ebook" - })); -}); - build.commandEbook(prog.command('pdf [source_dir]')) .description('Build a gitbook as a PDF') .action(function(dir, options) { diff --git a/lib/generate/ebook/index.js b/lib/generate/ebook/index.js index 0c5a664..cec0909 100644 --- a/lib/generate/ebook/index.js +++ b/lib/generate/ebook/index.js @@ -15,11 +15,6 @@ var stringUtils = require("../../utils/string"); */ var Generator = function() { BaseGenerator.apply(this, arguments); - - // Options for eBook generation - this.options = _.defaults(this.options, { - extension: "epub" - }); }; util.inherits(Generator, BaseGenerator); @@ -29,7 +24,7 @@ Generator.prototype.finish = function() { return BaseGenerator.prototype.finish.apply(this) .then(function() { var d = Q.defer(); - var format = that.options.extension || path.extname(that.options.output); + var format = that.options.extension || path.extname(that.options.output).replace("\.", "") || "pdf"; if (!that.options.cover && fs.existsSync(path.join(that.options.output, "cover.jpg"))) { that.options.cover = path.join(that.options.output, "cover.jpg"); @@ -46,21 +41,33 @@ Generator.prototype.finish = function() { }; if (format == "pdf") { + var pdfOptions = _.defaults(that.options.pdf || {}, { + "fontSize": 12, + "toc": true, + "paperSize": "a4", + "margin": { + "right": 62, + "left": 62, + "top": 36, + "bottom": 36 + } + }); + _.extend(_options, { - "--margin-left": "62", - "--margin-right": "62", - "--margin-top": "36", - "--margin-bottom": "36", - "--pdf-add-toc": true, - "--pdf-default-font-size": "12", - "--paper-size": "a4", + "--margin-left": String(pdfOptions.margin.left), + "--margin-right": String(pdfOptions.margin.right), + "--margin-top": String(pdfOptions.margin.top), + "--margin-bottom": String(pdfOptions.margin.bottom), + "--pdf-add-toc": Boolean(pdfOptions.toc), + "--pdf-default-font-size": String(pdfOptions.fontSize), + "--paper-size": String(pdfOptions.paperSize), }); } var command = [ "ebook-convert", path.join(that.options.output, "index.html"), - path.join(that.options.output, "index."+that.options.extension), + path.join(that.options.output, "index."+format), stringUtils.optionsToShellArgs(_options) ].join(" "); |