Get the width and height of the document pages

You can get the width and height of each document page using the getViewInfo method that returns a ViewInfo object. Use the getPages method to access the collection that contains each Page of the document.

The following code snippet shows how to get the width and height of each document page:

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.ViewInfoOptions;
import com.groupdocs.viewer.results.ViewInfo;
// ...

try (Viewer viewer = new Viewer("sample.pdf")) {
    // Get file information.
    ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();
    ViewInfo viewInfo = viewer.getViewInfo(viewInfoOptions);

    // Display width and height of each page.
    for (Page page : viewInfo.getPages()) {
        System.out.println("Page: " + page.getNumber() + "; Width: " + page.getWidth() + ", pixels");
        System.out.println("Page: " + page.getNumber() + "; Height: " + page.getHeight() + ", pixels");
    }
}

The following image shows a sample console output: