NodeJS and PDFKit: how to make first page to be landscape?

10.7k Views Asked by At

So, I've got a document:

var doc = new PDFDocument;

The docs tells me that The first page of a PDFKit document is added for you automatically, so there's no need to add it manualy. But how can I meke it to be landscape?

This one

doc.addPage({
    size: 'LEGAL',
    layout: 'landscape'
});

works, but adds another page.

3

There are 3 best solutions below

1
On BEST ANSWER

So it was quite obvious:

var doc = new PDFDocument(
        {
            layout : 'landscape'
        }
    );
0
On

You can disable autoFirstPage

const doc = new PDFDocument({ autoFirstPage: false });
doc.addPage({
    size: 'LEGAL',
    layout: 'landscape'
});

0
On

Using NodeJs you can just configure the PDF Document (without add pages)

//import the module
const PDFDocument = require("pdfkit-table");
//start pdf document
let doc = new PDFDocument({ 
                margin: 30, 
                size: 'A3', 
                layout: 'landscape' 
});