Hello,
public void shouldTestImportParagraphIntoSdt() throws Exception {
Path tempDirPath = Files.createTempDirectory(“shouldTestImportParagraphIntoSdt”);
String tempDir = tempDirPath + File.separator;
System.out.println(tempDirPath);
Document doc1 = new Document(getResourceAsStream(RESOURCE_DOCX_TEXT_WithContentControl4Aspose));
Document doc2 = new Document(getResourceAsStream(RESOURCE_DOCX_PARAGRAPHWITHFORMATTING));
// Remofe Aspose Watermark to properly test formatting;
doc2.getFirstSection().getBody().getFirstParagraph().remove();
DocumentBuilder documentBuilder = new DocumentBuilder(doc1);
NodeCollection collection = doc1.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
for (StructuredDocumentTag sdt : collection) {
switch (sdt.getTag()) {
case “sdtBlock”:
sdt.removeAllChildren();Paragraph para = new Paragraph(doc1);
sdt.appendChild(para);documentBuilder.moveTo(para);documentBuilder.insertDocument(doc2, ImportFormatMode.USE_DESTINATION_STYLES);
break;
case “sdtInline”:
sdt.removeAllChildren();
Run r = new Run(doc1);
sdt.appendChild®;
documentBuilder.moveTo®;
documentBuilder.insertDocument(doc2, ImportFormatMode.USE_DESTINATION_STYLES);
break;
}
}
insertDocument |
|
public Node insertDocument(Document srcDoc, int importFormatMode) |
-
Inserts content of the document into the current position of DocumentBuilder’s cursor. This method mimics the MS Word behavior, as if CTRL+‘A’ (select all content) was pressed, then CTRL+‘C’ (copy selected into the buffer) inside one document and then CTRL+‘V’ (insert content from the buffer) inside another document.- Parameters:
-
srcDoc
- Source document for inserting. -
importFormatMode
- A ImportFormatMode value. Specifies how to merge style formatting that clashes.
- Returns:
- First inserted node.