Click or drag to resize

DocumentBuilder Class

Provides methods to insert text, images and other content, specify character, paragraph and section formatting.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentDocumentBuilder

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public sealed class DocumentBuilder

The DocumentBuilder type exposes the following members.

Constructors
 NameDescription
Public methodDocumentBuilder Initializes a new instance of the DocumentBuilder class.
Public methodDocumentBuilder(DocumentCore) Initializes a new instance of the DocumentBuilder class.
Top
Properties
 NameDescription
Public propertyCode exampleCellFormat Gets the current table cell formatting properties.
Public propertyCode exampleCharacterFormat Gets current character formatting properties.
Public propertyCurrentPosition Gets the current insert position.
Public propertyDocument Gets the DocumentCore that this DocumentBuilder is attached to.
Public propertyCode exampleListFormat Gets the current list formatting properties.
Public propertyCode examplePageSetup Gets the current page setup and section properties.
Public propertyCode exampleParagraphFormat Gets the current paragraph formatting properties.
Public propertyCode exampleRowFormat Gets the current table row formatting properties.
Public propertyCode exampleTableFormat Gets the current table formatting properties.
Top
Methods
 NameDescription
Public methodCode exampleDeleteRow Deletes a row from a table.
Public methodCode exampleEndBookmark Marks the current position in the document as a bookmark end.
Public methodCode exampleEndRow Ends a table row in the document.
Public methodCode exampleEndTable Ends a table in the document.
Public methodCode exampleInsertCell Inserts a table cell into the document.
Public methodCode exampleInsertCheckBox(String, Boolean, Int32) Inserts a checkbox form field at the current position.
Public methodCode exampleInsertCheckBox(String, Boolean, Boolean, Int32) Inserts a checkbox form field at the current position.
Public methodCode exampleInsertComboBox Inserts a combobox form field at the current position.
Public methodCode exampleInsertContentControl Inserts a content control into a document.
Public methodInsertDocument(DocumentCore) Inserts a document at the cursor position.
Public methodInsertDocument(DocumentCore, ImportSession) Inserts a document at the cursor position.
Public methodCode exampleInsertField(String) Inserts a Word field into a document.
Public methodCode exampleInsertField(String, String) Inserts a Word field into a document.
Public methodCode exampleInsertHtml(String) Inserts an HTML string into the document.
Public methodCode exampleInsertHtml(String, Boolean) Inserts an HTML string into the document.
Public methodCode exampleInsertHyperlink Inserts a hyperlink into the document.
Public methodCode exampleInsertImage(Byte, NullableSize) Inserts an image from a byte array into the document. The image is inserted inline and at 100% scale.
Public methodCode exampleInsertImage(Stream, NullableSize) Inserts an image from a stream into the document. The image is inserted inline and at 100% scale.
Public methodCode exampleInsertImage(String, NullableSize) Inserts an image from a file into the document. The image is inserted inline and at 100% scale.
Public methodCode exampleInsertImage(Byte, HorizontalPosition, VerticalPosition, WrappingStyle, NullableSize) Inserts an image from a byte array at the specified position and size.
Public methodCode exampleInsertImage(Stream, HorizontalPosition, VerticalPosition, WrappingStyle, NullableSize) Inserts an image from a stream at the specified position and size.
Public methodCode exampleInsertImage(String, HorizontalPosition, VerticalPosition, WrappingStyle, NullableSize) Inserts an image from a file at the specified position and size.
Public methodInsertInline Inserts an Inline at the current position.
Public methodCode exampleInsertNote(NoteType, String) Inserts a footnote or endnote into the document.
Public methodCode exampleInsertNote(NoteType, String, String) Inserts a footnote or endnote into the document.
Public methodCode exampleInsertParagraph Inserts an Paragraph at the current position.
Public methodCode exampleInsertSection Inserts a section into the document.
Public methodCode exampleInsertShape(Figure, Size) Inserts inline shape with specified figure and size.
Public methodCode exampleInsertShape(Figure, HorizontalPosition, VerticalPosition, WrappingStyle, Size) Inserts free-floating shape with specified position, size and text wrap style.
Public methodCode exampleInsertSpecialCharacter Inserts a special character into the document.
Public methodCode exampleInsertTableOfContents Inserts a table of contents into the document.
Public methodCode exampleInsertTextInput Inserts a text form field at the current position.
Public methodCode exampleMoveTo Moves the cursor to a given position.
Public methodCode exampleMoveToBookmark(String) Moves the cursor to a bookmark.
Public methodCode exampleMoveToBookmark(String, Boolean, Boolean) Moves the cursor to a bookmark.
Public methodCode exampleMoveToCell Moves the cursor to a specified position inside table in the current section.
Public methodCode exampleMoveToDocumentEnd Moves the cursor to the end of the document.
Public methodCode exampleMoveToDocumentStart Moves the cursor to the beginning of the document.
Public methodCode exampleMoveToField Moves the cursor to a field in the document.
Public methodCode exampleMoveToHeaderFooter Moves the cursor to the beginning of a header or footer in the current section.
Public methodCode exampleMoveToMergeField(String) Moves the cursor to a position just beyond the specified merge field and removes the merge field.
Public methodCode exampleMoveToMergeField(String, Boolean, Boolean) Moves the cursor to the specified merge field.
Public methodCode exampleMoveToParagraph Moves the cursor to a paragraph in the current section.
Public methodCode exampleMoveToSection Moves the cursor to the beginning of a specified section.
Public methodCode examplePopCharacterFormat Retrieves character formatting previously saved on the stack.
Public methodCode examplePushCharacterFormat Saves current character formatting onto the stack.
Public methodCode exampleStartBookmark Marks the current position in the document as a bookmark start.
Public methodCode exampleStartTable Inserts a table into the document.
Public methodCode exampleWrite Inserts a string into the document at the current insert position.
Public methodCode exampleWriteln Inserts a paragraph break into the document.
Public methodCode exampleWriteln(String) Inserts a string and a paragraph break into the document.
Top
Example

See Developer Guide: Create a document and insert a string of text using DocumentBuilder

How to insert formatted text using DocumentBuilder in C#
using System;
using SautinSoft.Document;
using System.Text;


namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/
            InsertingText();
        }
        /// <summary>
        /// Create a document and insert a string of text using DocumentBuilder.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/documentbuilder-inserting-text.php
        /// </remarks>

        static void InsertingText()
        {
            DocumentCore dc = new DocumentCore();
            DocumentBuilder db = new DocumentBuilder(dc);

            string resultPath = @"Result.pdf";

            // Insert the formatted text into the document using DocumentBuilder.
            db.CharacterFormat.FontName = "Verdana";
            db.CharacterFormat.Size = 55.5f;
            db.CharacterFormat.AllCaps = true;
            db.CharacterFormat.Italic = true;
            db.CharacterFormat.FontColor = Color.Orange;
            db.Write("insert a text using");

            db.InsertSpecialCharacter(SpecialCharacterType.LineBreak);

            db.CharacterFormat.Size = 52.5f;
            db.CharacterFormat.FontColor = Color.Blue;
            db.CharacterFormat.AllCaps = false;
            db.CharacterFormat.Italic = false;
            db.Write("DocumentBuilder");

            // Save the document to the file in PDF format.
            dc.Save(resultPath, new PdfSaveOptions()
            { Compliance = PdfCompliance.PDF_A1a });

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true });
        }
    }
}
How to insert formatted text using DocumentBuilder in VB.Net
Imports System
Imports SautinSoft.Document
Imports System.Text


Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            InsertingText()
        End Sub
                ''' Get your free 30-day key here:   
                ''' https://sautinsoft.com/start-for-free/
        ''' <summary>
        ''' Create a document and insert a string of text using DocumentBuilder.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/documentbuilder-inserting-text.php
        ''' </remarks>

        Private Shared Sub InsertingText()
            Dim dc As New DocumentCore()
            Dim db As New DocumentBuilder(dc)

            Dim resultPath As String = "result.pdf"

            ' Insert the formatted text into the document using DocumentBuilder.
            db.CharacterFormat.FontName = "Verdana"
            db.CharacterFormat.Size = 55.5F
            db.CharacterFormat.AllCaps = True
            db.CharacterFormat.Italic = True
            db.CharacterFormat.FontColor = Color.Orange
            db.Write("insert a text using")

            db.InsertSpecialCharacter(SpecialCharacterType.LineBreak)

            db.CharacterFormat.Size = 52.5F
            db.CharacterFormat.FontColor = Color.Blue
            db.CharacterFormat.AllCaps = False
            db.CharacterFormat.Italic = False
            db.Write("DocumentBuilder")

            ' Save the document to the file in PDF format.
            dc.Save(resultPath, New PdfSaveOptions() With {.Compliance = PdfCompliance.PDF_A1a})

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