Cloning

Document element instances in GemBox.Document can be only at one single location in a document at a time. To insert a document element into some other part of the same document, it must be cloned and the clone should be inserted.

Following example demonstrates how to clone document elements, first by cloning a section and its content, and then by individually cloning section content elements – blocks.

Cloning Screenshot
Upload your file (Drag file here)
using System.Linq;
using GemBox.Document;

class Program
{
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("%InputFileName%");

        // Clone section
        document.Sections.Add(document.Sections[0].Clone(true));

        // Clone paragraphs
        foreach (Block item in document.Sections[0].Blocks)
            document.Sections.Last().Blocks.Add(item.Clone(true));

        document.Save("Cloning.%OutputFileType%");
    }
}
Imports System.Linq
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        ' Clone section
        document.Sections.Add(document.Sections(0).Clone(True))

        ' Clone paragraphs
        For Each item As Block In document.Sections(0).Blocks
            document.Sections.Last().Blocks.Add(item.Clone(True))
        Next

        document.Save("Cloning.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.