Click or drag to resize

DocumentCoreCalculateStats Method

Calculates document's statistics (number of words, number of pages and etc).

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public void CalculateStats()
Remarks
Appropriate properties of BuiltIn will be updated.

Note:

The trial version calculates the number of words with a small error, because of random inserting of word "trial".
The full version calculates the number of words completely correctly.
Example

See Developer Guide: Calculates the number of words, pages and characters in a document

Calculates the number of words, pages and characters in a document in C#
using System;
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using System.IO;
using System.Linq;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            CalculateStatistics();
        }

        /// <summary>
        /// Calculates the number of words, pages and characters in a document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/counting-words-paragraphs-net-csharp-vb.php
        /// </remarks>
        static void CalculateStatistics()
        {
            // Load a DOCX file.
            string filePath = @"..\..\..\words.docx";

            DocumentCore dc = DocumentCore.Load(filePath);

            // Update and count the number of words and pages in the file.
            dc.CalculateStats();

            // Show statistics.
            Console.WriteLine("Pages: {0}", dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Pages]);
            Console.WriteLine("Paragraphs: {0}", dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Paragraphs]);
            Console.WriteLine("Words: {0}", dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Words]);
            Console.WriteLine("Characters: {0}", dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Characters]);
            Console.WriteLine("Characters with spaces: {0}", dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.CharactersWithSpaces]);
        }
    }
}
Calculates the number of words, pages and characters in a document in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        CalculateStatistics()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Calculates the number of words, pages and characters in a document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/counting-words-paragraphs-net-csharp-vb.php
    ''' </remarks>
    Sub CalculateStatistics()
        ' Load a DOCX file.
        Dim filePath As String = "..\..\..\words.docx"

        Dim dc As DocumentCore = DocumentCore.Load(filePath)

        ' Update and count the number of words and pages in the file.
        dc.CalculateStats()

        ' Show statistics.
        Console.WriteLine("Pages: {0}", dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Pages))
        Console.WriteLine("Paragraphs: {0}", dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Paragraphs))
        Console.WriteLine("Words: {0}", dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Words))
        Console.WriteLine("Characters: {0}", dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Characters))
        Console.WriteLine("Characters with spaces: {0}", dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.CharactersWithSpaces))
    End Sub
End Module
See Also