MATLAB: How to create mixed orientation pages in the report generator PDF

generatorlandscapeMATLABmixedorientationpagepdfportraitreport

I am using report generator to create a PDF and I would like certain pages to have landscape orientation and the rest to have portrait orientation. I know that if I want to set my full report to landscape orientation, I do:
>> rpt.Layout.Landscape = true;
How do I do this for individual pages?

Best Answer

The best way to do this would be to put your desired landscape pages in their own chapter and then setting the chapter layout to landscape:
>> ch.Layout.Landscape = true;
If you want individual pages within chapters to have mixed orientation, then you have to follow a couple of steps:
1. Create the chapter.
2. Add any content that you want in portrait landscape to the chapter.
3. Add a PDFPageLayout obj and have it oriented to landscape with the width and height changed:
>> PageLayoutObj = mlreportgen.dom.PDFPageLayout;
>> PageLayoutObj.PageSize.Orientation = 'landscape';
>> PageLayoutObj.PageSize.Height = '8.5in';
>> PageLayoutObj.PageSize.Width = '11in';
4. Add the landscape page layout object to the chapter
5. Then add any content you want on that page to the chapter. Be careful to make sure this content does not exceed that one landscape page. You can ensure you don't exceed a single page by placing the content inside an invisible table that is 10.5in by 8in.
Please see the attached example for how to change a chapter's orientation and how to change an individual page's orientation.