Insert Documents
With RadWordsProcessing, you have the ability to insert a document into another document at specified position.
Inserting Documents at a Specific Position
You could merge documents at a specific position using the InsertDocument() method of the RadFlowDocumentEditor class. When called, this method inserts the source document at the current editor position.
public void InsertDocument(RadFlowDocument sourceDocument)
-
public void InsertDocument(RadFlowDocument sourceDocument, InsertDocumentOptions insertOptions)
The sourceDocument variable represents the document, which should be inserted (merged) at the specified location.
-
InsertDocumentOptions: Represents the options, which should be used while inserting is performed. This class contains information about:
ConflictingStylesResolutionMode: Determines how conflicts between styles should be resolved (rename the style of the source or keep the target settings). The default value is RenameSourceStyle.
InsertLastParagraphMarker: Determines whether the last paragraph marker (last paragraph formatting symbol) should be inserted. If the value is true, then a new paragraph with the same formatting will be inserted. Otherwise, only the inlines from that paragraph will be inserted. The default value is true.
Example 1 demonstrates how to use the InsertDocument() method.
Example 1: Insert source document into target document
InsertDocumentOptions options = new InsertDocumentOptions();
options.ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.UseTargetStyle;
options.InsertLastParagraphMarker = true;
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(targetDocument);
editor.InsertDocument(sourceDocument, options);
Behavior
Table 1 lists some scenarios where the InsertDocument() method could be used.
Table 1
Action | Result |
---|---|
Insert the source document in an empty document (without any sections). | All of the content of the source document will be inserted in the target one. The section properties will be obtained from the source document. |
Insert the source document between runs. Source document contains a single section. | All of the blocks (Paragraphs and Tables) in the source document’s section will be inserted at the specific location. The section properties will be omitted. This means if the target document page orientation is portrait and the source is landscape, the result document will have portrait orientation. |
Insert the source document between runs. Source document contains multiple sections. | All of the blocks in the source document’s first section will be inserted at the current editor position. All the next sections from the source document will be inserted as separate sections. The last section in the result document will have section properties of the section from the target document where the editor position is when the InsertDocument() method is invoked. |
Insert the source document at the beginning of the target document. Source document contains single section. | All of the blocks in the source document’s section will be inserted at the specific location. The section properties will be omitted. This means if the target document page orientation is portrait and the source is landscape, the result document will have portrait orientation. |
Insert the source document at the beginning of the target document. Source document contains multiple sections. | All of the blocks in the source document’s first section will be inserted at the specific location. The whole next sections from the source document will be inserted as separate sections. The last section in the result document will have section properties of the insert target section. |
Insert the source document at the end of the target document. Source document contains single section. | All of the blocks in the source document’s section will be inserted at the specific location. The section properties will be omitted. This means if the target document page orientation is portrait and the source is landscape, the result document will have portrait orientation. |
Insert the source document at the end of the target document. Source document contains multiple sections. | Same as the above. |
Insert the source document in a table cell and the source document contains multiple sections. | An InvalidOperationException is thrown. |
Source document contains no Sections. | An ArgumentException is thrown. |