We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

When inserting document into inline SDT- Aspose applies paragraph formatting instead of run formatting

Hello,


Aspose Version: 15.8.0

please see attached documents for clarification:
- Document_WithContentControl_4Aspose.docx: Base document
- ParagraphWithFormatting.docx: Imported document
- outInsert.docx: Result, with addition of manual copy/paste to compare

When using the code below to import data into an inline SDT, all run formatting of this paragraph is ignored. Only the paragraph formatting is used.
Wenn using word copy/paste (strg+a,c,v) to insert the data into the SDT, exactly the opposite behaviour can be observed.

Is there a way to reproduce word behaviour?

Thanks,
Alexander
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)
throws java.lang.Exception
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.

Hi Alexander,

Thanks for your inquiry. There are three content controls in your document. The type of all content controls is “RichText”. So, please use following code snippet for all content controls.

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin-top:0pt; mso-para-margin-right:0pt; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0pt; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

sdt.removeAllChildren();

Paragraph para = new Paragraph(doc1);

sdt.appendChild(para);

documentBuilder.moveTo(para);

documentBuilder.insertDocument(doc2, ImportFormatMode.USE_DESTINATION_STYLES);


In sdtBlock switch case, you are not adding the paragraph in content control. Please add an empty paragraph to content control after remove all children of content control.

If you still face problem, please share following detail for investigation purposes.

  • Please

    create a standalone/runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
    your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,


thank you for your reply.

So, please use following code snippet for all content controls.

This is not possible since you cannot add a paragraph to a inline level content control.

In sdtBlock switch case, you are not adding the paragraph in content control.
Thank you for pointing this out. I have corrected the sample code above. The problem persists since I made this error when writing this post, not when writing my test.

As to your requested details:

Please create a standalone/runnable simple Java application that demonstrates
The code provided should be completely standalone, you only have to insert the references to the documents for your system.

  • Please attach the output Word file that shows the undesired behavior.
  • Please attach your target Word document showing the desired behavior.
See attached outInsert.docx in original posting. it shows both the undesired and the desired result. I have revised all attached documents to further clarify my problem.

Best regards,
Alexander

Hi Alexander,

Thanks for sharing the detail. Please note that Aspose.Words mimics the same behavior as MS Word does. If you copy the contents of ParagraphWithFormatting.docx into content controls using MS Word, you will get the same output.

DocumentBuilder.InsertDocument method 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.

Hi Tahir,


thank you for your reply.

However, it is not correct. If you paste the content into an inline content control, the result differs between Apose and Word.

Output of Aspose:

The
following inline level SDT will show the undesired data<w:sdt docpart=“83E6CDEE0FBF4CE4AA5460CF12908633” title=“sdtInline” sdttag=“sdtInline” id=“1380046053”> <span style=“font-size:16.0pt;line-height:107%;font-family:“Calibri Light”,sans-serif;
mso-ascii-theme-font:major-latin;mso-fareast-font-family:“MS Gothic”;
mso-fareast-theme-font:major-fareast;mso-hansi-theme-font:major-latin;
mso-bidi-font-family:“Times New Roman”;mso-bidi-theme-font:major-bidi;
color:#2E74B5;mso-themecolor:accent1;mso-themeshade:191”>This Paragraph is
formatted as Heading 1 Mit Fußnote. However Mit Endnote, several runs have
different formatting.
</w:sdt>

Output of Word:

This is the
expected result for inline level SDT: <w:sdt showingplchdr=“t” docpart=“851865987ABD4715A5143C3B3FB77D7E” title=“sdtExpected” sdttag=“sdtExpected” id="-1379087463">This Paragraph is formatted as Heading 1<span lang=“EN-US” style=“font-size:11.0pt;
line-height:107%;font-family:“Calibri”,sans-serif;mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:“MS Mincho”;mso-fareast-theme-font:minor-fareast;
mso-hansi-theme-font:minor-latin;mso-bidi-font-family:“Times New Roman”;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
JA;mso-bidi-language:AR-SA”>[1]
. However<span lang=“EN-US” style=“font-size:11.0pt;line-height:107%;font-family:“Calibri”,sans-serif;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:“MS Mincho”;
mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:“Times New Roman”;mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-US;mso-fareast-language:JA;mso-bidi-language:AR-SA”>[i]
,
several runs have different formatting.</w:sdt>



[1] Mit Fußnote



[i] Mit Endnote

Hi Alexander,

Thanks
for sharing the detail. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-12528. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-12528) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.