Get the PDF output file information

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

You can get the information about the PDF output file using the getViewInfo method that returns a ViewInfo object. The object contains the Pages collection that represents each Page of the document.

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

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

    // Display page count.
    System.out.println("Pages count: " + viewInfo.getPages().size());

    // 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: