Document .Net - Create a new document

Create a document

Document .Net supports these formats:

PDF DOCX RTF HTML
Create/Read/Write Create/Read/Write Create/Read/Write Create/Read/Write

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 demonstation 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 demonstation purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub
End Module

Download.

© SautinSoft 2002 - 2018