I was just going through the documentation for pdfmake where they give the following code for setting page orientation:
var docDefinition = { // a string or { width: number, height: number } pageSize: 'A5', // by default we use portrait, you can change it to landscape if you wish pageOrientation: 'landscape', ... //Other content };
Now the essence of this entire project is the Document definition object which is unique I guess. Even on the github page and the issues mentioned, I don't see a provision of setting page orientation for specific pages although you can add PageBreaks like so:
(...) 'You can also fit the image inside a rectangle', { image: 'fonts/sampleImage.jpg', fit: [100, 100], pageBreak: 'after' }, (...)
That said, I do think there is a workaround for your problem. You see, this is how the pdf document is generated in this project:
var fs = require('fs'); var pdfDoc = printer.createPdfKitDocument(docDefinition); pdfDoc.pipe(fs.createWriteStream('pdfs/basics.pdf')); pdfDoc.end();
Ofcourse the pipe and fs modules are node implementations. However, since we have page orientation attached to a document definition object, if we have multiple doc definitions like so:
var pdf1 = printer.createPdfKitDocument(docdef1); //landscape mode page 1 var pdf2 = printer.createPdfKitDocument(docdef2); //portrait mode page 2 var pdf3 = printer.createPdfKitDocument(docdef3); //landscape mode for the rest of the pages.
We can now just use the append flag in the createWriteStream() method. Useful documentation. (Untested code)
pdf1.pipe(fs.createWriteStream('foo.pdf')); pdf2.pipe(fs.createWriteStream('foo.pdf',{flags:'a'})); pdf3.pipe(fs.createWriteStream('foo.pdf',{flags:'a'})); pdf1.end(); pdf2.end(); pdf3.end();
I was just suggesting how you might go about combining document definition objects. Hope it gets you started in the right direction.