We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Find the page Orientation in document

Hi Team,

How to find the page Orientation for the particular page number. i try this below code but an exception has occurred.

My code:

	LayoutCollector collector = new LayoutCollector(doc);
	Iterable<Shape> shapes = doc.getChildNodes(NodeType.SHAPE, true);
	for (Shape s: shapes)
	{
	    try {
			if (s.hasImage())
				System.out.println(doc.getSections().get(collector.getStartPageIndex(s)).getPageSetup().getOrientation());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Exception:
java.lang.NullPointerException
at com.wer.wsx.findImage.findLanscapeImage(findImage.java:747)
at com.wer.wsx.findImage.imageExtraction(findImage.java:668)
at com.wer.wsx.findImage.createFolderAIE(findImage.java:555)
at com.wer.wsx.findImage.main(findImage.java:182)

@Mahesh39 Page number is not section index. MS Word document is flow document and it does not have Page concept. Pages layout is built on the fly when you open the document by consumer app. You should use the following code:

LayoutCollector collector = new LayoutCollector(doc);
Iterable<Shape> shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape s: shapes)
{
    try
    {
        if (s.hasImage()) {
            System.out.println(((Section)s.getAncestor(NodeType.SECTION)).getPageSetup().getOrientation() == Orientation.LANDSCAPE);
            System.out.println(collector.getStartPageIndex(s));
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}