diff --git a/index.js b/index.js index 9339e1a..13aa5ec 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,12 @@ docmake.prototype.getPdf = function(options) { options.size = options.size || 'A4'; options.margins = options.margins || { top: 10, left: 10, right: 10, bottom: 10 }; options.fonts = options.fonts || fonts; - var doc = new PdfKit({size: options.size, margins: [0, 0, 0, 0]}); + options.layout = options.layout || 'portrait'; + var doc = new PdfKit({ + size: options.size, + margins: [0, 0, 0, 0], + layout: options.layout + }); var document = new Document(options, doc); var rootContext = { parent: document, diff --git a/tests/landscape.js b/tests/landscape.js new file mode 100644 index 0000000..4830d58 --- /dev/null +++ b/tests/landscape.js @@ -0,0 +1,43 @@ +/* eslint-disable */ +var assert = require('assert'); +var Docmake = require('../index'); + +describe('Landscape/Portrait', function () { + it('should generate a printable pdf in landscape mode', function (done) { + var template = `{{text "test landscape"}}`; + var doc = new Docmake(); + var buffers = []; + doc.compile(template, {}, function(err) { + if (err) { + return done(err); + } + var doc_pdf = doc.getPdf({ layout : 'landscape' }); + doc_pdf.on('data', function(buffer) { + buffers.push(buffer); + }); + doc_pdf.on('end', function() { + assert.strictEqual(doc_pdf.page.layout, 'landscape'); + done(); + }); + }); + }); + + it('should generate a printable pdf in portrait mode', function (done) { + var template = `{{text "test portrait"}}`; + var doc = new Docmake(); + var buffers = []; + doc.compile(template, {}, function(err) { + if (err) { + return done(err); + } + var doc_pdf = doc.getPdf({}); + doc_pdf.on('data', function(buffer) { + buffers.push(buffer); + }); + doc_pdf.on('end', function() { + assert.strictEqual(doc_pdf.page.layout, 'portrait'); + done(); + }); + }); + }); +}); \ No newline at end of file