Get file info

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());
    }
}