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();
        }

        static void CreateDocument()
        {
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hello World!", new CharacterFormat() { FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange });
            dc.Save("Result.docx");

            // Open the result for demonstation purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("Result.docx") { UseShellExecute = true });
        }
    }
}

Download.

        
            Imports SautinSoft.Document

Module ExampleVB

    Sub Main()
        CreateDocument()
    End Sub

    Sub CreateDocument()
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hello World!", New CharacterFormat() With {
                .FontName = "Verdana",
                .Size = 65.5F,
                .FontColor = Color.Orange
            })
        dc.Save("Result.docx")

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

Download.

© SautinSoft 2019