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

Free Support Forum - aspose.com

First bullet removed during ImportNode. Merging of two documents

Hi Daniel,


Thanks for your inquiry

Do you mean that the first bullet is lost using the above method? Currently this is the expected behavior, a bullet can only appear paragraph wide, not within that specific part of text. In your example you would need to have the entire line including Heading Text with a bullet point. How would you like things to appear in this case?

Regarding your second point, it shouldn’t matter where the content is inserted, when you remove a bookmark it should only remove the bookmark itself and not the content in between. Please try using the code below.

doc.Range.Bookmarks[“MyBookmark”].Remove();<o:p></o:p>


Thanks,

Adam, you are right about the bookmark. I just noticed that we actually have a BookMark.Text = "" in our code since we label our bookmarks on the template. I know how to fix this. However, regarding the bullet scenario, I guess I have two type of inserts and will need to handle them differently.

MAIN TEMPLATE

Heading Text: [BOOKMARK1] //In this case, removing bullet is expected
behavior since can't start bullet in middle of sentence

Heading Text2:
[BOOKMARK2]. // In this case, I will want bullet to be inserted correctly. So I would
need to use InsertDocument method instead. Only problem is I still
want it to start in the line the bookmark is at. Is there a way for me
to once I call the insert document method I can delete the previous
line so current insert moves up a line?

I want final generation to look like below except I want bullet to be right under the Heading Text2. I guess is a combination of the InsertDocument for when bullets are present and the other for when just inserting text.

Heading Text: This text came from Document1

Heading Text2:

  • This text came from Document2
  • This text also came from Document2

I think I know what I need to do except for the question posted above. Really appreciate all the help.

Adam,

Another question, is there a way I can scan the src document and determine if it starts with a bullet or similar paragraph formatting?

Thanks again.

Adam,

I was able to use the document's VariableCollection to add a variable and tag the document accordingly. We actually create the src document before adding it to the main document since is a combination of various options. Now, when the first run is added to the document, I check to see if bullets are added initially and tag the document to use the InsertDocument method. I almost have a final solution. Only thing pending is that extra line/paragraph where the original bookmark used to be. Because the bookmark is on a paragraph and the new document gets added in a new paragraph, I always get blank line above my new text. I tried removing paragraph by finding bookmark and then doing bookmark.parentnode.remove(). This however, did not work. Any suggestion on how I can do this right?

Thanks,
Daniel

Hi Daniel,


Thanks for the additional information. It is perfect that you managed to resolve the first part of your problem. Secondly, may be you can implement the following work flow to be able to remove extra paragraph above the newly inserted document:

  1. Insert a Run node with some dummy text in the Paragraph where the Bookmark resides.
  2. Insert your document at the Bookmark
  3. Once the document is inserted, instead of seeing an empty Paragraph, you should now see a line of dummy text above the document.
  4. Find the dummy text (in main document) by using the code suggested in the following article and remove the parent Paragraph. (This will remove the dummy text along with extra line spacing): http://docs.aspose.com/display/wordsnet/IReplacingCallback+Interface
  5. Finally remove the Bookmark (if it still exists)

I hope, this will help.

Best Regards,

Hi there,


Thanks for your inquiry.

Additionally you can also find if a source document begins with list item by using the code below.

<span style=“font-size:10.0pt;line-height:115%;font-family:
“Courier New”;color:blue;mso-no-proof:yes”>bool<span style=“font-size:
10.0pt;line-height:115%;font-family:“Courier New”;mso-no-proof:yes”>
firstParaIsList = srcDoc.FirstSection.Body.FirstParagraph.IsListItem;


You can then choose what method to use to insert the document based on this.

Please let us know if the code Awais has provided works for you, we will be glad to assist you further if you need any help.

Thanks,

Thank you so much. This information makes things a lot cleaner and ultimately don't have to bother with document varialbes. I also solved the empty paragraph problem after InsertDocument with the following. Do you suggest a better way?

virtual protected void HandleEmptyParaAfterInsertDocument(string bookmarkName){

BookmarkStart bmStart = _template.Range.Bookmarks[bookmarkName].BookmarkStart;
CompositeNode bmStartParent = bmStart.ParentNode;
if (AsposeUtil.IsEmptyParagraph(bmStartParent)){
bmStartParent.Remove();
}

}

public static bool IsEmptyParagraph(Node node){

bool rc = false;
if (node.NodeType == NodeType.Paragraph){

Aspose.Words.Paragraph para = (Aspose.Words.Paragraph)node;
if (para.ChildNodes.Count == 0){

rc = true;

}
else{

if (para.Range.Text == "\r"){

rc = true; // assume true unless we find embedded excel object
foreach (Node childNode in para.ChildNodes){

if (childNode.NodeType == NodeType.Shape){

rc = false;
break;

}

}

}

}

}

return rc;

}

I also needed a way to cleanup the document before inserting into the main one. Particularly, dealing with multiple empty paragraphs at the end of the document. I created this method. Which seems to work, but again, is there a better way which Aspose already handles this?

public static void DocumentCleanUp(Document document){

NodeCollection lastChildren = document.LastSection.Body.ChildNodes;

int highIdx = lastChildren.Count - 1;

Node childNode = null;

// Remove trailing paragraph breaks

for (int i = highIdx; i >= 0; i--){

childNode = lastChildren[i];

if (childNode.NodeType != NodeType.Paragraph || ((Aspose.Words.Paragraph)childNode).HasChildNodes){

break;

}

else{

childNode.Remove();

}

}

}

Thanks for ALL the help. You guys are the best!!! Truely best support I've ever experienced.

Actually, this piece of code should do what the Document Cleanup currently does, right?

//Remove empty paragraphs from the end of document

while (!((CompositeNode)srcDoc.LastSection.Body.LastChild).HasChildNodes){

srcDoc.LastSection.Body.LastParagraph.Remove();

if (srcDoc.LastSection.Body.LastChild == null)

break;

}

Hi there,


Thanks for your inquiry.

Both code snippets appear to work correctly, the second appears the most concise so I would go with that.

If we can help with anything else, please feel free to ask.

Thanks,

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


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