Get document info
Leave feedback
On this page
GroupDocs.Conversion provides a standard way of obtaining information about the source document. It works regardless of how the document was loaded: from a disk, a stream, or cloud storage.
To get document information, use the Converter.GetDocumentInfo() method. It returns a DocumentInfo object with common information common for every supported document - format, creation date, size, and page count.
To iterate through the document information properties, use the PropertyNames
and Item
enumerators. The following code snippet shows how to list all the available document information properties:
using (Converter converter = new Converter("sample.txt"))
{
IDocumentInfo info = converter.GetDocumentInfo();
foreach (var propertyName in info.PropertyNames)
{
Console.WriteLine(propertyName + ": "+ info[propertyName]);
}
}
Depending on the format type, the resulting DocumentInfo
object also contains some additional information:
- PDF documents - title, table of contents, author, whether it is encrypted and so on;
- Wordprocessing documents - title, table of contents, author, lines count, words count, whether it is password protected and so on;
- Project management documents - project start and end dates, number of tasks;
- Images - width, height, bits per pixel;
- Presentations - title, author, whether it is password protected;
- Spreadsheets - title, author, worksheets count, whether it is password protected;
- CAD drawings - width, height, collections of layouts and layers;
- Emails - number and names of attachments, whether it is encrypted, whether it is signed, whether its body is in HTML format;
See the API reference for a complete list of format-specific document metadata.
The samples below show how to obtain document info for various formats.
using (Converter converter = new Converter("sample-toc.pdf"))
{
IDocumentInfo info = converter.GetDocumentInfo();
PdfDocumentInfo docInfo = (PdfDocumentInfo) info;
Console.WriteLine("Author: {0}", docInfo.Author);
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Title: {0}", docInfo.Title);
Console.WriteLine("Version: {0}", docInfo.Version);
Console.WriteLine("Pages count: {0}", docInfo.PagesCount);
Console.WriteLine("Width: {0}", docInfo.Width);
Console.WriteLine("Height: {0}", docInfo.Height);
Console.WriteLine("Is landscaped: {0}", docInfo.IsLandscape);
Console.WriteLine("Is Encrypted: {0}", docInfo.IsEncrypted);
foreach (var tocItem in docInfo.TableOfContents)
{
Console.WriteLine($"{tocItem.Title}: {tocItem.Page}");
}
}
using (Converter converter = new Converter("sample.doc"))
{
IDocumentInfo info = converter.GetDocumentInfo();
WordProcessingDocumentInfo docInfo = (WordProcessingDocumentInfo) info;
Console.WriteLine("Author: {0}", docInfo.Author);
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Is Password Protected: {0}", docInfo.IsPasswordProtected);
Console.WriteLine("Lines: {0}", docInfo.Lines);
Console.WriteLine("Pages count: {0}", docInfo.PagesCount);
Console.WriteLine("Size: {0}", docInfo.Size);
Console.WriteLine("Title: {0}", docInfo.Title);
Console.WriteLine("Words: {0}", docInfo.Words);
foreach (var tocItem in docInfo.TableOfContents)
{
Console.WriteLine($"{tocItem.Title}: {tocItem.Page}");
}
}
using (Converter converter = new Converter("foobar.mpp"))
{
IDocumentInfo info = converter.GetDocumentInfo();
ProjectManagementDocumentInfo docInfo = (ProjectManagementDocumentInfo) info;
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Start date: {0}", docInfo.StartDate);
Console.WriteLine("End date: {0}", docInfo.EndDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Size: {0}", docInfo.Size);
Console.WriteLine("Tasks count: {0}", docInfo.TasksCount);
}
using (Converter converter = new Converter("image.png"))
{
IDocumentInfo info = converter.GetDocumentInfo();
ImageDocumentInfo docInfo = (ImageDocumentInfo) info;
Console.WriteLine("Bits per pixel: {0}", docInfo.BitsPerPixel);
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Height: {0}", docInfo.Height);
Console.WriteLine("Width: {0}", docInfo.Width);
Console.WriteLine("Size: {0}", docInfo.Size);
}
using (Converter converter = new Converter("presentation.ppt"))
{
IDocumentInfo info = converter.GetDocumentInfo();
PresentationDocumentInfo docInfo = (PresentationDocumentInfo) info;
Console.WriteLine("Author: {0}", docInfo.Author);
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Is Password Protected: {0}", docInfo.IsPasswordProtected);
Console.WriteLine("Pages count: {0}", docInfo.PagesCount);
Console.WriteLine("Size: {0}", docInfo.Size);
Console.WriteLine("Title: {0}", docInfo.Title);
}
using (Converter converter = new Converter("table.xlsx"))
{
IDocumentInfo info = converter.GetDocumentInfo();
SpreadsheetDocumentInfo docInfo = (SpreadsheetDocumentInfo) info;
Console.WriteLine("Author: {0}", docInfo.Author);
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Is Password Protected: {0}", docInfo.IsPasswordProtected);
Console.WriteLine("Pages count: {0}", docInfo.PagesCount);
Console.WriteLine("Size: {0}", docInfo.Size);
Console.WriteLine("Title: {0}", docInfo.Title);
Console.WriteLine("Worksheets Count : {0}", docInfo.WorksheetsCount);
}
using (Converter converter = new Converter("sample.dwg"))
{
IDocumentInfo info = converter.GetDocumentInfo();
CadDocumentInfo docInfo = (CadDocumentInfo) info;
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Height: {0}", docInfo.Height);
Console.WriteLine("Width: {0}", docInfo.Width);
Console.WriteLine("Size: {0}", docInfo.Size);
foreach (var layout in docInfo.Layouts)
{
Console.WriteLine($"Layout: {layout}");
}
foreach (var layer in docInfo.Layers)
{
Console.WriteLine($"Layer: {layer}");
}
}
using (Converter converter = new Converter("sample.msg"))
{
IDocumentInfo info = converter.GetDocumentInfo();
EmailDocumentInfo docInfo = (EmailDocumentInfo) info;
Console.WriteLine("Creation date: {0}", docInfo.CreationDate);
Console.WriteLine("Format: {0}", docInfo.Format);
Console.WriteLine("Is Encrypted: {0}", docInfo.IsEncrypted);
Console.WriteLine("Is body in HTML: {0}", docInfo.IsHtml);
Console.WriteLine("Is Signed: {0}", docInfo.IsSigned);
Console.WriteLine("Size: {0}", docInfo.Size);
Console.WriteLine("Attachments Count: {0}", docInfo.AttachmentsCount);
foreach (var attachmentName in docInfo.AttachmentsNames)
{
Console.WriteLine($"Attachment Name: {attachmentName}");
}
}
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.