Beispiel #1
0
        /// <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]);
        }
Beispiel #2
0
        /// <summary>
        /// Create a new document (DOCX) with some built-in properties.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/document-properties.php
        /// </remarks>
        public static void CreateDocumentProperties()
        {
            string filePath = @"..\..\DocumentProperties.docx";

            DocumentCore dc = new DocumentCore();

            // Let's create a simple inscription.
            dc.Content.End.Insert("Hello World!!!", new CharacterFormat()
            {
                FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange
            });

            // Let's add some documents properties: Author, Subject, Company.
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Title]              = "How to add document properties. It works with DOCX, RTF, PDF, HTML etc";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Company]            = "SautinSoft";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Author]             = "John Smith";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Subject]            = "Document .Net";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Keywords]           = "reader, writer, docx, pdf, html, rtf, text";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.HyperlinkBase]      = "www.sautinsoft.com";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Manager]            = "Alex Dickard";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Category]           = "Document Object Model (DOM)";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.DateContentCreated] =
                new DateTime(2010, 1, 10).ToString();
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.DateLastSaved] =
                DateTime.Now.ToString();

            dc.CalculateStats();

            // Save our document to DOCX format.
            dc.Save(filePath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath)
            {
                UseShellExecute = true
            });
        }