Combining Runs with Identical Formatting

Does Aspose.Words provide a method to combine adjacent runs with identical formatting into a single run? Such a method would be very helpful, because it would allow us to split runs more liberally during document manipulation, since we would be able to put them back together again afterward.

Indeed, with OpenXML (WordProcessingML), a very common and efficient procedure for complex text manipulation involves splitting a paragraph into runs of single characters, performing the manipulation, and then putting the runs back together as relevant. A Microsoft advocate for OpenXML, Eric White, has written about this method, and has provided the functions to perform both the split operation as well as the combine operation, over here:
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2012/04/18/working-with-wordprocessingml-paragraphs-and-runs-how-to-insert-a-bookmark.aspx

I am aware that the Aspose.Words sample code includes a function to split runs, but as far as I can tell a function to combine runs is missing. Please do supply such a function; Aspose.Words should be at least as easy to use as OpenXML! (Or, if I’ve missed it, please do let me know where I can find sample code for this operation).

I have seen a previous post some years ago with a similar request over here:
Combine adjacent runs with identical formatting?
However, the thread did not indicate any resolution. Has there been a resolution to that issue?

Actually, I think I just found it: it is the JoinRunsWithSameFormatting() method. (I had been searching for “combining” rather than “joining”, and hence I didn’t find it at first).

I’d advise adding a note to the aforementioned thread from the Aspose.Words forum so that users who search and find that issue will also be advised of its resolution.

Hi Shmidman,

Thanks for your inquiry. Yes, Document.JoinRunsWithSameFormatting method joins runs with same formatting in all paragraphs of the document. It is nice to hear from you that you have solved your problem. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

The truth is, I would prefer a Join routine that could be used on a paragraph-by-paragraph basis; as it stands now, the JoinRunsWithSameFormatting() routine can only be run on the entire document at once.

I work with very long documents (500-1000 pages). If I break up each paragraph into individual runs and then wait until the end to join them all together, I suspect that the document will become unwieldy. Conversely, if I run the JoinRunsWithSameFormatting() routine again and again after each paragraph, there will be a large overhead cost, because it will inspect the entire document each time.

Would it be possible to provide a JoinRunsWithSameFormatting() routine which would work only on a specified paragraph? Alternatively, would it be possible to provide the source for this helper routine, so that we would be able to integrate it as needed in our code?

Hi,

Thanks for the additional information. We will consider providing a method similar to Document.JoinRunsWithSameFormatting that checks a single Paragraph node in the document for adjacent Run nodes having identical properties and then joins those Run nodes into one. I have logged a new feature request in our bug tracking system. The ID of this feature is WORDSNET-7279. Your request has been linked to this feature and you will be notified as soon as it is available. Sorry for the inconvenience.

Best Regards,

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

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

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan