Document .Net - Create a new document

Create a document


Document .Net supports these formats:

Let's create a simple document with "Hello World!" text:

A simple document - Hello World!

Main steps

  1. Notice you are importing the SautinSoft.Document namespace.
    using SautinSoft.Document;
  2. First of all, create an instance of DocumentCore.
    
    DocumentCore dc = new DocumentCore();
    
    DocumentCore is root class, it represents a document itself.
  3. Add text "Hello World!" into our document.
    
    dc.Content.End.Insert("Hello World!");
    
    ContentRange represents an area in document as a contiguous sequence of characters boundend by start and end positions. It allows to insert and extract data in a streaming manner in(from) desired positions.
 

Complete code

using SautinSoft.Document;

namespace Example
{
    class Program
    {        
        static void Main(string[] args)
        {
            CreateDocument();
        }
		
        /// <summary>
        /// Creates a new document and saves it in a desired format.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/create-document.php
        /// </remarks>
        static void CreateDocument()
        {            
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hello World!", new CharacterFormat() { FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange });

            // Save a document to a file in DOCX format.
            string filePath = @"Result.docx";
            dc.Save(filePath);

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

Download.

        
            Imports SautinSoft.Document

Module Sample
    Sub Main()
        CreateDocument()
    End Sub

    ''' <summary>
    ''' Creates a new document and saves it in a desired format.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/create-document.php
    ''' </remarks>
    Sub CreateDocument()
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hello World!", New CharacterFormat() With {
                .FontName = "Verdana",
                .Size = 65.5F,
                .FontColor = Color.Orange
            })

        ' Save a document to a file in DOCX format.
        Dim filePath As String = "Result.docx"
        dc.Save(filePath)

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

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.

© SautinSoft 2002 - 2019