Click or drag to resize

DocumentCore Class

The main class of "Document .Net" library. Represents a document itself.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentElement
    SautinSoft.DocumentDocumentCore

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax
public sealed class DocumentCore : Element, 
	IContentElement

The DocumentCore type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleDocumentCore Initializes a new instance of the DocumentCore class.
Top
Properties
 NameDescription
Public propertyCode exampleBookmarks Gets the document bookmarks.
Public propertyComments Gets the document comments.
Public propertyCustomXmlParts Gets the custom XML parts contained in this document.
Public propertyCode exampleDefaultCharacterFormat Gets or sets the default character format.
Public propertyCode exampleDefaultParagraphFormat Gets or sets the default paragraph format.
Public propertyEditProtection Gets or sets the document protection settings used to restrict editing and formatting of document content. Supported in DOCX format.
Public propertyElementType Gets the ElementType of this element instance.
(Overrides ElementElementType)
Public propertyCode exampleMailMerge Gets a MailMerge object that represents the mail merge functionality for the document.
Public propertyCode exampleProperties Gets the document properties.
Public propertyCode exampleRenderRightToLeft Gets or sets render right to left. (default false)
Public propertyCode exampleRevisions Gets a collection of revisions (tracked changes) that exist in this document.
Public propertyCode exampleSections Gets a collection that represents all sections in the document.
Public propertyStatic memberCode exampleSerialObsolete.
This property is obsolete, please use the method SetLicense(String).
Public propertySettings Gets or sets the document settings.
Public propertyCode exampleStyles Gets a collection of styles defined in the document.
Public propertyWriteProtection Gets the document write protection options. Supported only in DOCX format.
Top
Methods
 NameDescription
Public methodCalculateListItems Calculates the list items contained in this document.
Public methodCalculateListItems(Boolean) Calculates the list items contained in this document.
Public methodCode exampleCalculateStats Calculates document's statistics (number of words, number of pages and etc).
Public methodClone Clones this DocumentCore instance.
Public methodCode exampleGetPaginator Gets the document paginator.
Public methodCode exampleGetPaginator(PaginatorOptions) Gets the document paginator.
Public methodCode exampleImportT(T, Boolean) Imports (clones) the specified source element to this DocumentCore instance so it can be inserted into document content.
Public methodCode exampleImportT(T, Boolean, ImportSession) Imports (clones) the specified source element to this DocumentCore instance so it can be inserted into document content.
Public methodStatic memberCode exampleLoad(String) Loads a document from a file with the specified path.
Public methodStatic memberCode exampleLoad(Stream, LoadOptions) Loads a document from the specified stream.
Public methodStatic memberCode exampleLoad(String, LoadOptions) Loads a document from a file or URL.
Public methodCode exampleSave(String) Saves the document to a file with the specified path. Path must include file extension.
Public methodCode exampleSave(Stream, SaveOptions) Saves the document in the specified stream.
Public methodCode exampleSave(String, SaveOptions) Saves the document to a file with the specified path.
Public methodStatic memberCode exampleSetLicense
Activate your copy after purchasing or use temporary license for delete trial message. ATTENTION: specify this property first of all before creating the instance of DocumentCore!

Use it when you got own license. We offer two license types:

Permanent license from sautinsoft.com and

Temporary license from https://sautinsoft.com/start-for-free/.

Have question? Ask us: support@sautinsoft.com.
Top
Example

See Developer Guide: How to create a new document and saves it in a desired format

How to create a new document and saves it in a desired format in C#
using SautinSoft.Document;

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

            // You can create the same document by using 3 ways:
            // 
            //  + DocumentBuilder
            //  + DOM directly
            //  + DOM and ContentRange
            // 
            // Choose any of them which you like.

            // Way 1:
            CreateUsingDocumentBuilder();

            // Way 2:
            CreateUsingDOM();

            // Way 3:
            CreateUsingContentRange();
        }

        /// <summary>
        /// Creates a new document using DocumentBuilder and saves it in a desired format.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-document.php
        /// </remarks>
        static void CreateUsingDocumentBuilder()
        {
            // Create a new document and DocumentBuilder.
            DocumentCore dc = new DocumentCore();
            DocumentBuilder db = new DocumentBuilder(dc);

            // Specify the formatting and insert text.
            db.CharacterFormat.FontName = "Verdana";
            db.CharacterFormat.Size = 65.5f;
            db.CharacterFormat.FontColor = Color.Orange;
            db.Write("Hello World!");

            // Save the document in DOCX format.
            string outFile = "DocumentBuilder.docx";
            dc.Save(outFile);

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
        }
        /// <summary>
        /// Creates a new document using DOM and saves it in a desired format.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-document.php
        /// </remarks>
        static void CreateUsingDOM()
        {
            // Create a new document.
            DocumentCore dc = new DocumentCore();

            // Create a new section,
            // add the section the document.
            Section sect = new Section(dc);
            dc.Sections.Add(sect);

            // Create a new paragraph,
            // add the paragraph to the section.
            Paragraph par = new Paragraph(dc);
            sect.Blocks.Add(par);

            // Create a new run (text object),
            // add the run to the paragraph.
            Run run = new Run(dc, "Hello World!");
            run.CharacterFormat.FontName = "Verdana";
            run.CharacterFormat.Size = 65.5f;
            run.CharacterFormat.FontColor = Color.Orange;
            par.Inlines.Add(run);

            // Save the document in PDF format.
            string outFile = @"DOM.pdf";
            dc.Save(outFile);

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

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


        /// <summary>
        /// Creates a new document using DOM and ContentRange and saves it in a desired format.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-document.php
        /// </remarks>
        static void CreateUsingContentRange()
        {
            // Create a new document.
            DocumentCore dc = new DocumentCore();
            // Insert the formatted text into the document.
            dc.Content.End.Insert("Hello World!", new CharacterFormat() { FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange });

            // Save the document in HTML format.
            string outFile = @"ContentRange.html";
            dc.Save(outFile, new HtmlFixedSaveOptions() { Title = "ContentRange" });

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
        }
    }
}
How to create a new document and saves it in a desired format in VB.Net
Imports SautinSoft.Document

Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            ' You can create the same document by using 3 ways:
            '
            '  + DocumentBuilder
            '  + DOM directly
            '  + DOM and ContentRange
            '
            ' Choose any of them which you like.

            ' Way 1:
            CreateUsingDocumentBuilder()

            ' Way 2:
            CreateUsingDOM()

            ' Way 3:
            CreateUsingContentRange()
        End Sub
                ''' Get your free 100-day key here:   
                ''' https://sautinsoft.com/start-for-free/

        ''' <summary>
        ''' Creates a new document using DocumentBuilder and saves it in a desired format.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-document.php
        ''' </remarks>
        Private Shared Sub CreateUsingDocumentBuilder()
            ' Create a new document and DocumentBuilder.
            Dim dc As New DocumentCore()
            Dim db As New DocumentBuilder(dc)

            ' Specify the formatting and insert text.
            db.CharacterFormat.FontName = "Verdana"
            db.CharacterFormat.Size = 65.5F
            db.CharacterFormat.FontColor = Color.Orange
            db.Write("Hello World!")

            ' Save the document in DOCX format.
            Dim outFile As String = "DocumentBuilder.docx"
            dc.Save(outFile)

            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
        End Sub
        ''' <summary>
        ''' Creates a new document using DOM and saves it in a desired format.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-document.php
        ''' </remarks>
        Private Shared Sub CreateUsingDOM()
            ' Create a new document.
            Dim dc As New DocumentCore()

            ' Create a new section,
            ' add the section the document.
            Dim sect As New Section(dc)
            dc.Sections.Add(sect)

            ' Create a new paragraph,
            ' add the paragraph to the section.
            Dim par As New Paragraph(dc)
            sect.Blocks.Add(par)

            ' Create a new run (text object),
            ' add the run to the paragraph.
            Dim run As New Run(dc, "Hello World!")
            run.CharacterFormat.FontName = "Verdana"
            run.CharacterFormat.Size = 65.5F
            run.CharacterFormat.FontColor = Color.Orange
            par.Inlines.Add(run)

            ' Save the document in PDF format.
            Dim outFile As String = "DOM.pdf"
            dc.Save(outFile)

            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
        End Sub


        ''' <summary>
        ''' Creates a new document using DOM and ContentRange and saves it in a desired format.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-document.php
        ''' </remarks>
        Private Shared Sub CreateUsingContentRange()
            ' Create a new document.
            Dim dc As New DocumentCore()
            ' Insert the formatted text into the document.
            dc.Content.End.Insert("Hello World!", New CharacterFormat() With {
                .FontName = "Verdana",
                .Size = 65.5F,
                .FontColor = Color.Orange
            })

            ' Save the document in HTML format.
            Dim outFile As String = "ContentRange.html"
            dc.Save(outFile, New HtmlFixedSaveOptions() With {.Title = "ContentRange"})

            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also