Click or drag to resize

Layout Class

Represents a base class for specifying element's layout properties, such as position and size.
Inheritance Hierarchy

Namespace: SautinSoft.Document.Drawing
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public abstract class Layout

The Layout type exposes the following members.

Properties
 NameDescription
Public propertyCode exampleSize Gets or sets the size.
Top
Methods
 NameDescription
Public methodStatic memberCode exampleFloating Creates a layout used when element should be floating in a document page and rest of the page content should wrap around it.
Public methodStatic memberCode exampleGroup Creates a layout used when element should be within a group.
Public methodStatic memberCode exampleInline Creates a layout used when element should be embedded in-line with the rest of the content.
Top
Example

See Developer Guide: How to add pictures into a document

How to add pictures into a document in C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;

namespace Sample
{
    class Sample
    {

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

            AddPictures();
        }

        /// <summary>
        /// How to add pictures into a document. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-pictures.php
        /// </remarks>
        public static void AddPictures()
        {
            string documentPath = @"Pictures.docx";
            string pictPath = @"..\..\..\image1.jpg";

            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Add a new section.
            Section s = new Section(dc);
            dc.Sections.Add(s);

            // 1. Picture with InlineLayout:

            // Create a new paragraph with picture.
            Paragraph par = new Paragraph(dc);
            s.Blocks.Add(par);
            par.ParagraphFormat.Alignment = HorizontalAlignment.Left;

            // Add some text content.
            par.Content.End.Insert("Shrek and Donkey ", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black });

            // Our picture has InlineLayout - it doesn't have positioning by coordinates
            // and located as flowing content together with text (Run and other Inline elements).
            Picture pict1 = new Picture(dc, InlineLayout.Inline(new Size(100, 100)), pictPath);

            // Add picture to the paragraph.
            par.Inlines.Add(pict1);

            // Add some text content.
            par.Content.End.Insert(" arrive at Farquaad's palace in Duloc, where they end up in a tournament.", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black });

            // 2. Picture with FloatingLayout:
            // Floating layout means that the Picture (or Shape) is positioned by coordinates.
            Picture pict2 = new Picture(dc, pictPath);
            pict2.Layout = FloatingLayout.Floating(
                new HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page),
                new VerticalPosition(70, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point),
                         LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point))
                         );

            // Set the wrapping style.
            (pict2.Layout as FloatingLayout).WrappingStyle = WrappingStyle.Square;

            // Add our picture into the section.
            s.Content.End.Insert(pict2.Content);

            // Save our document into DOCX format.
            dc.Save(documentPath, new DocxSaveOptions());

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to add pictures into a document in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing

Module Sample
    Sub Main()
        AddPictures()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' How to add pictures into a document. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-pictures.php
    ''' </remarks>
    Sub AddPictures()
        Dim documentPath As String = "Pictures.docx"
        Dim pictPath As String = "..\..\..\image1.jpg"

        ' Let's create a simple document.
        Dim dc As New DocumentCore()

        ' Add a new section.
        Dim s As New Section(dc)
        dc.Sections.Add(s)

        ' 1. Picture with InlineLayout:

        ' Create a new paragraph with picture.
        Dim par As New Paragraph(dc)
        s.Blocks.Add(par)
        par.ParagraphFormat.Alignment = HorizontalAlignment.Left

        ' Add some text content.
        par.Content.End.Insert("Shrek and Donkey ", New CharacterFormat() With {
            .FontName = "Calibri",
            .Size = 16.0,
            .FontColor = Color.Black
        })

        ' Our picture has InlineLayout - it doesn't have positioning by coordinates
        ' and located as flowing content together with text (Run and other Inline elements).
        Dim pict1 As New Picture(dc, InlineLayout.Inline(New Size(100, 100)), pictPath)

        ' Add picture to the paragraph.
        par.Inlines.Add(pict1)

        ' Add some text content.
        par.Content.End.Insert(" arrive at Farquaad's palace in Duloc, where they end up in a tournament.", New CharacterFormat() With {
            .FontName = "Calibri",
            .Size = 16.0,
            .FontColor = Color.Black
        })

        ' 2. Picture with FloatingLayout:
        ' Floating layout means that the Picture (or Shape) is positioned by coordinates.
        Dim pict2 As New Picture(dc, pictPath)
        pict2.Layout = FloatingLayout.Floating(New HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page), New VerticalPosition(70, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), New Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point), LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point)))

        ' Set the wrapping style.
        TryCast(pict2.Layout, FloatingLayout).WrappingStyle = WrappingStyle.Square

        ' Add our picture into the section.
        s.Content.End.Insert(pict2.Content)

        ' Save our document into DOCX format.
        dc.Save(documentPath, New DocxSaveOptions())

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