pdfmake: How to create multiple page pdf with different orientation?

Ismail Sunny picture Ismail Sunny · Nov 4, 2014 · Viewed 23.1k times · Source

is there a way to create multiple page pdf with different page orientation using pdfmake?

to make it simple, I want something like this :

  • Page 1 with portrait orientation
  • page 2 with landscape orientation
  • page 3 with portrait orientation

I've tried it so many times with different method but it always effect to all page.


sorry for my terible english

Answer

RandomUser picture RandomUser · Jun 2, 2015

This is and old question, but answering may help others.

If you want to change page orientation you only need specify the new value at the first node of the page.

Below this lines I have attached a simple code that you can paste directly at pdfmake playground in order to try it.

Good luck!

var dd = {
    content: [
        { 
            text: 'Unordered list', 
            style: 'header' 
        },
        {
            ol: [
                'item 1',
                'item 2',
                'item 3',
            ]
        },
        { 
             text: '\n\nUnordered list with longer lines', 
             style: 'header', 
             pageBreak: 'before', 
             pageOrientation: 'landscape' 
        },
        {
            ol: [
                'item 1',
                'Lorem ipsum dolor sit amet, consectetur ..',
                'item 3',
            ]
        },
        { 
            text: '\n\nNested lists', 
            style: 'header', 
            pageBreak: 'before', 
            pageOrientation: 'portrait' 
        },
        {
            ol: [
                'item 1',
                'Lorem ipsum dolor sit amet, consectetur ..',
                {
                    ol: [
                        'subitem 1',
                        'subitem 2',
                        'subitem 3 - Lorem ipsum dolor sit ame...',
                        'subitem 4',
                        'subitem 5',
                    ]
                },
                'item 3\nsecond line of item3',
            ]
        },
    ],
    styles: {
        header: {
            bold: true,
            fontSize: 15
        }
    },
    defaultStyle: {
        fontSize: 12,
    }   
}