package com.aspose.words.examples.programming_documents.document;

import com.aspose.words.Document;
import com.aspose.words.examples.Utils;

public class CloneDocument {

	public static final String dataDir = Utils.getSharedDataDir(CloneDocument.class) + "Document/";

	public static void main(String[] args) throws Exception {
		// ExStart:CloneDocument
		// Load the document from disk.
		Document doc = new Document(dataDir + "Document.doc");

		Document clone = doc.deepClone();

		// Save the document to disk.
		clone.save(dataDir + "TestFile_clone_out.doc");
		// ExEnd:CloneDocument
	}

}

@@ -84,24 +84,133 @@
 e.words.
-Document
+BreakType;%0Aimport com.aspose.words.Document;%0Aimport com.aspose.words.DocumentBuilder;%0Aimport com.aspose.words.Section
 ;%0Aimport
@@ -431,16 +431,115 @@
 ption %7B%0A
+%09%09CloneDocument();%0A%09%09CloneADocument();%0A%09%7D%0A%09%0A%09public static void CloneDocument() throws Exception %7B%0A
 %09%09// ExS
@@ -768,16 +768,16 @@
 .doc%22);%0A
-
 %09%09// ExE
@@ -795,12 +795,1065 @@
 ument%0A%09%7D
+%0A%09%0A%09public static void CloneADocument() throws Exception %7B%0A%09%09// ExStart:CloneADocument%0A%09%09// Create a document.%0A%09%09Document doc = new Document();%0A%09%09DocumentBuilder builder = new DocumentBuilder(doc);%0A%09%09builder.writeln(%22This is the original document before applying the clone method%22); %0A%0A%09%09// Clone the document.%0A%09%09Document clone = doc.deepClone();%0A%0A%09%09// Edit the cloned document.%0A%09%09builder = new DocumentBuilder(clone);%0A%09%09builder.write(%22Section 1%22);%0A%09%09builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);%0A%09%09builder.write(%22Section 2%22);%0A%0A%09%09// This shows what is in the document originally. The document has two sections.%0A%09%09System.out.println(clone.getText().trim());%0A%0A%09%09// Duplicate the last section and append the copy to the end of the document.%0A%09%09int lastSectionIdx = clone.getSections().getCount() - 1;%0A%09%09Section newSection = clone.getSections().get(lastSectionIdx).deepClone();%0A%09%09clone.getSections().add(newSection);%0A%0A%09%09// Check what the document contains after we changed it.%0A%09%09System.out.println(clone.getText().trim());%0A%09%09//ExEnd:CloneADocument%0A%09%7D
 %0A%0A%7D%0A

Update CloneDocument.java