Get file info

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.Comparison 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-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

GroupDocs.Comparison allows you to get the following file information:

  • FileType represents the document file type (PDF, Word document, Excel spreadsheet, PowerPoint presentation or image etc.).
  • PageCount represents count of document pages.
  • FileSize represents the document file size.
  • PagesInfo represents the page information.

The following code samples show how to get file information:

Get file info for the file from local disk

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.interfaces.IDocumentInfo;
// ...

try (Comparer comparer = new Comparer("source.docx")) {
    IDocumentInfo info = comparer.getSource().getDocumentInfo();
    for (int i = 0; i < info.getPageCount(); i++) {
        System.out.printf("\n" +
                        "File type: %s\n" +
                        "Number of pages: %d\n" +
                        "Document size: %d bytes\n" +
                        "Width: %d\n" +
                        "Height: %d%n",
                info.getFileType().getFileFormat(), 
                info.getPageCount(), 
                info.getSize(), 
                info.getPagesInfo().get(i).getWidth(), 
                info.getPagesInfo().get(i).getHeight());
    }
}

The result is as follows:

Get file info for the file from stream

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.interfaces.IDocumentInfo;
import java.io.FileInputStream;
import java.io.InputStream;
// ...

try (InputStream inputStream = new FileInputStream("source.docx");
    Comparer comparer = new Comparer(inputStream)) {
    IDocumentInfo info = comparer.getSource().getDocumentInfo();
    for (int i = 0; i < info.getPageCount(); i++) {
        System.out.printf("\n" +
                        "File type: %s\n" +
                        "Number of pages: %d\n" +
                        "Document size: %d bytes\n" +
                        "Width: %d\n" +
                        "Height: %d%n",
                info.getFileType().getFileFormat(), 
                info.getPageCount(), 
                info.getSize(), 
                info.getPagesInfo().get(i).getWidth(), 
                info.getPagesInfo().get(i).getHeight());
    }
}