GroupDocs.Viewer exposes two inspection methods on the Viewer class:
get_file_info() — returns a FileInfo result with the detected file type and name. Cheap; no rendering required.
get_view_info(options) — returns a ViewInfo result that includes the page count, per-page dimensions, and format-specific metadata. Takes a ViewInfoOptions created with one of the for_html_view() / for_png_view() / for_jpg_view() / for_pdf_view() factory methods.
For several format families, get_view_info returns a format-specific subclass of ViewInfo that exposes extra properties:
Format family
Result type
Extra properties
PDF
PdfViewInfo
printing_allowed
Archive (ZIP / RAR / 7Z)
ArchiveViewInfo
folders
CAD (DWG / DXF / DGN)
CadViewInfo
layers, layouts
Outlook (PST / OST)
OutlookViewInfo
folders
Project (MPP / MPT)
ProjectManagementViewInfo
start_date, end_date
Cast the ViewInfo result to the appropriate subclass to access the extra properties.
Example 1: Get File Type and Pages Count
The following code snippet shows how to get the file type and the page count for any supported document:
fromgroupdocs.viewerimportViewerfromgroupdocs.viewer.optionsimportViewInfoOptionsdefget_file_type_and_pages_count():# Load PDF documentwithViewer("sample.pdf")asviewer:info=viewer.get_view_info(ViewInfoOptions.for_html_view())print("Document type:",info.file_type)print("Pages count:",len(info.pages))if__name__=="__main__":get_file_type_and_pages_count()
sample.pdf is the sample file used in this example. Click here to download it.
Document type: Portable Document Format File (.pdf)
Pages count: 2
sample.pst is the sample file used in this example. Click here to download it.
File type: Outlook Personal Information Store File (.pst)
Pages count: 1
Folders:
Inbox
Deleted Items
Outbox
Sent Items
Calendar
Contacts
Drafts
[TRUNCATED]