RadFlowDocumentEditor FindAll results unexpected

0 Answers 45 Views
WordsProcessing
Patrick
Top achievements
Rank 1
Patrick asked on 06 Feb 2024, 01:12 PM | edited on 06 Feb 2024, 01:14 PM

I created a test docx with the following text in a justified format:

"This is a brand-new document with justified text.  Putting extra text into the paragraph in order to highlight the specific justified format text.  This is simply test text in order to demonstrate the issue that I am having when I attempt to use the Telerik rad document find all."

I then upload the document into Session and save the file binary by converting the File.InputStream to Base64Stream.

I then create a find text of "This is simply test text".

The resulting IReadOnlyCollection<FindResult> of editor.FindAll(txtFind, false, true); contains one result with three runs.

"highlight the specific justified format text. This is simply"

"test"

"text in order to demonstrate the issue that I am having when I attempt to use the Telerik rad document find all.

 

I had assumed that setting match whole word would return a better result, but it does not.

I think I do not understand the concept of "runs".  There is no other formatting other than justification.  

I expected either the sentence that the text resides in to return OR the entire paragraph.  Not three incomplete sentences, one just including one word.

Patrick
Top achievements
Rank 1
commented on 08 Feb 2024, 06:37 PM

Also, cannot search for items with a single quote?
Yoan
Telerik team
commented on 09 Feb 2024, 09:49 AM

Hello Patrick,

I was able to reproduce the described issue on my end as well and after some investigation, I managed to identify the cause for this behavior.

When creating a document, Word offers suggestions, highlights spelling mistakes, etc:

Because of this, some parts of the text have different styling (in this case they are underlined) which causes them to be separated from the main text block as standalone runs with their own separate properties. I have come to the conclusion that if these suggestions are manually removed/turned off and then the document is saved, the whole text will be regarded as one Run once again:

That said, even though this happens it shouldn't really be a setback as I have tested the Replace functionality as well and it seems to be working as expected even if the text is separated into several runs.

However, your case and requirements might be different so please feel free to share more details about the scenario you are in and how this behavior affects you. This way I might be able to help you by coming up with a custom solution. 

As for the single quote search, I was able to observe it as well. I will look into it so for the time being I can only suggest you use the Regex approach instead.

Let me know if you have any additional questions.

Regards,

Yoan

Patrick
Top achievements
Rank 1
commented on 09 Feb 2024, 12:51 PM | edited

Thanks Yoan that makes sense.  

My own R&D is making strides with a better understanding of how it works.

Hypothetically, we are looking at using radflowdocument to build a system that can:

1. Find and replace text in a document as it is "built" from an uploaded document template based on logical conditions.  i.e. If a specific condition is true, replace a paragraph with a different paragraph.

2. Find text across multiple documents in a library and display a highlighted sub section along with the document name/library location.  i.e Find all document templates that contain the words "duly appointed" highlight and display along with the name of the document.  Future functionality would most likely require a batch replace.

3. Standard data MailMerge. i.e.  We would have a standard model of data fields that our users could add to their documents that would auto replace the values into the document at build time.  I am finding documentation on adding fields at run time, but I'm finding no documentation on how to potentially add fields what would work with the mail merge to the document before it gets uploaded into the system.

I believe we can fill all these requirements using the word doc processing library.

What I'm finding mostly is that if I try to type the text into the find box, it will fail if there are any special characters (specifically single quotes) or like you stated erroneous word formatting in the original document.  If I copy and paste it from the original word doc it works perfectly fine (not ideal but we can work with that).  i.e. If I have the following text: "Recipient’s Counsel"  in a document, and I type "Recipient's Counsel" in the find text box, it comes back with nothing but if I copy and paste it from the original document it will highlight the whole section using: 

editor.ReplaceStyling(txtFind, false, false, new Action<Telerik.Windows.Documents.Flow.Model.Styles.CharacterProperties>((properties) =>
                {
                    properties.HighlightColor.LocalValue = Telerik.Documents.Media.Colors.Yellow;
                }));

Vladislav
Telerik team
commented on 14 Feb 2024, 07:35 AM

Hi, Patrick,

Yoan is out of the office today, and I will assist you.

As for the requirements:

1. You can find and replace text on demand using the WordsProcessing library.

2. You can find text across multiple documents and highlight the pre-defined text, but you will not be able to display the document contents using only the WordsProcessing library (you will need some kind of control for that).

3. You can add merge fields and perform a Mail merge with our library as well. Here is more information inside our documentation - Mail Merge. Information on how to add Merge fields to the document can be found in the Inserting Merge Fields section in the previous article.

As for the inability to find the text with a single quote - the reason for this is that when typing from the keyboard you are entering a different symbol from the one present in the document. Here is a screenshot:

You can see for yourself that the symbols on the two lines are different. When searching for a text string a match is found only if every symbol is the same. So you should use the method overrides using the Regex string as the input parameter instead, as my colleague Yoan suggested in the previous post.

I hope you will find this information helpful. If you have any difficulties implementing the desired behavior, you can contact us.

No answers yet. Maybe you can help?

Tags
WordsProcessing
Asked by
Patrick
Top achievements
Rank 1
Share this question
or