With GroupDocs.Comparison you can retrieve the following information about a file:
FileType represents the document file type (PDF, Word document, Excel spreadsheet, PowerPoint presentation, image etc.).
PageCount represents the number of pages in a document.
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 a local disk
The following example opens a local document and prints its basic metadata such as type, page count, and size.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Create a Comparer instance for the source document (loaded from disk)
constcomparer=newgroupdocs.Comparer('sample-files/source.docx');// Retrieve document information (type, pages, size, etc.) from the source
constinfo=comparer.getSource().getDocumentInfo();// Output file type, page count, and size to the console
console.log(`\nFile type: ${info.getFileType().getFileFormat()}`);console.log(`Number of pages: ${info.getPageCount()}`);console.log(`Document size: ${info.getSize()} bytes`);// Terminate the process with a success exit code
process.exit(0);
The result is as follows:
Get file info for the file from a stream
The following example loads a document from a Java input stream and then reads its metadata.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Import Java bridge to work with input streams
constjava=require('java');// Get a reference to the Java FileInputStream class
letInputStream=java.import('java.io.FileInputStream');// Create a Comparer instance using a Java input stream as the source document
constcomparer=newgroupdocs.Comparer(newInputStream('sample-files/source.docx'));// Retrieve document information from the source stream
constinfo=comparer.getSource().getDocumentInfo();// Print document type, page count, and size to the console
console.log(`\nFile type: ${info.getFileType().getFileFormat()}`);console.log(`Number of pages: ${info.getPageCount()}`);console.log(`Document size: ${info.getSize()} bytes`);// Terminate the process with a success exit code
process.exit(0);
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.