Free Support Forum - aspose.com

How to copy text with formating from the Range to rich text box?

I would like to know how can i implement the following code?

I need to copy a text (with formating) from some range in the document to the rich text box. By using word this was performed as following:

RichTextBox rt = new RichTextBox();

Range wRange = GetRangeFromField(wField,false); // getting range from bookmark

wRange.FormattedText.Copy();
rt.Paste();

Thanks.

Ok, i found answer here:


http://www.aspose.com/community/forums/202887/extract-rich-text-from-document/showthread.aspx#202887

Hello,

It's great that you find solution. If you have any other questions, feel free to ask. We would be glad to help you.

I still have some problem with RTF format:


I am extracting the rtf format from document’s bookmark.

When i am using word i am using the following code:

RichTextBox rt = new RichTextBox();
Range wRange = GetRangeFromField(wField,false);
wRange.FormattedText.Copy();
rt.Paste();

When i am using aspose i am using the following code:

Bookmark FieldBookmark = mDocument.Range.Bookmarks[“START” + wField.Id];

BookmarkStart bookmarkStart = FieldBookmark.BookmarkStart;
BookmarkEnd bookmarkEnd = FieldBookmark.BookmarkEnd;

// Firstly extract the content between these nodes including the bookmark.
ArrayList extractedNodes = ExtractContent(bookmarkStart, bookmarkEnd, false);

Document BookmarkContent = GenerateDocument(mDocument, extractedNodes);
BookmarkContent.Save(@“C:/Temp/temp7.doc”);

RichTextBox rt = new RichTextBox();

MemoryStream rtfStream = new MemoryStream();
SaveOptions options = SaveOptions.CreateSaveOptions(format);
options.PrettyFormat = true;
BookmarkContent .Save(rtfStream, options);
rt.Rtf = Encoding.UTF8.GetString(rtfStream.GetBuffer());

The formating in tmp7.doc is correct but when i am displaying the rich text box content i see the difference between RTF that i got using word and using aspose. As you can see from attached files RTF text formating that i got using aspose is incorrect (numbering font is incorrect). Is there any way to fix it?



Hello,

Thank you for your request.
How can I see your resulting document temp7.doc also incorrectly displays the list items. Could you please attach your original document. I'll try your code and give you more detailed information.

The tem7.doc displays numbering exactly as it is displayed in original document.

Original document attached.

I managed to reproduce your problem on my side.
I created an appropreate issue in our defect database. Once the problem is solved, we will notify you immediately.

Ok, thank you very much!

Can you give an estimation how much time will take to fix this issue because this issue is critical for us?

Hi

Thanks for your request. It is difficult to promise you something at this stage. Our developers will analyze the issue and provide you more information.

Best regards,

Hi Alexey,


Thank you for the reply. I just want to emphasize that it is very important for us. I am from Algotec company (that is part of Carestream company). Currently we are using the aspose for word to pdf conversion and now we also want to use aspose instead of word on server side.
We are going to release our next version during this month. This issue is critical for us to make a final decision whether we indeed can switch to use aspose or to stay with word.
I would like to know if you perhaps have an estimation when you can give me an answer for how much time will take to resolve this issue.

Thanks,
Stanislav.

Hi Alexey again,


I am sorry to bother but it is very important for us to get this estimation.

Hi Stanislav,

Thanks for your request. Unfortunately, as I mentioned earlier, I cannot provide you any estimate regarding the issue before our developers analyze of this issue. Once the issue is analyzed we will immediately provide you more information.

Best regards,

Thank you Alexey,


I completely understand that you cant tell me when this issue will be fixed before developers finish to analyze it. But my question was for your opinion how much time will take to finish analyze it? Are we talking about several days? several weeks? It is very important because we must to decide now whether we are going to switch to aspose in our current version.

Thanks,
Stanislav.

Hello,

Thank you for your inquiry.
We produce a release every 4-5 weeks. In late April we released version 10.0. Hence the next release will be only in late May - early June. And unfortunately I can not promise you that the fix enters into this release. I will add your request in my monthly report, it will increase the priority of the task. Sorry for the inconvenience.

Thank you,


So in this case maybe you can tell me how much time will take till you will know whether the fix of this issue will be in the next release or not?
Or maybe you can release for us dll that will contain fix for this issue only (before release)? I am asking that because i remember that we had a problem with converting word to pdf and aspose just sent fix for us in several days.

Thanks,
Stanislav.

Hi Stanislav,

Thanks for your request. Please expect a reply before the next hotfix (within 5-7 weeks). We can just fix the problem by then or provide you more information.

Also, you should note that RTF document produced by Aspose.Words looks fine in MS Word. Only RichTextBox does not show it properly. So this might be a bug in RichTextBox.

In addition, I found a simple workaround of the issue. Please try using the following code:

Document doc = new Document(@"Test001\in.doc");

Node[] paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).ToArray();

foreach (Paragraph paragraph in paragraphs)

{

if(paragraph.IsListItem)

{

paragraph.ListFormat.ListLevel.Font.Name = paragraph.ParagraphBreakFont.Name;

paragraph.ListFormat.ListLevel.Font.Size = paragraph.ParagraphBreakFont.Size;

paragraph.ListFormat.ListLevel.Font.Bold = paragraph.ParagraphBreakFont.Bold;

paragraph.ListFormat.ListLevel.Font.Italic = paragraph.ParagraphBreakFont.Italic;

paragraph.ListFormat.ListLevel.Font.Color = paragraph.ParagraphBreakFont.Color;

}

}

doc.Save(@"Test001\out.rtf");

Hope this helps.

Best regards,

Hello Alexey,


First of all thank you for help. You are doing really great job. The workaround that you provided solved part of the problem. But pay attention that font are still different between word and aspose rtf conversion.

I am attaching document.

First section as it was converted by rich text box when i used word (FormatedText property)
Second section as it was converted by rich text box when i used Aspose.
Third section as it was converted by rich text box when i used Aspose with workaround. As you can see text underline now is thiner then in original text although it was fine before workaround.

Hello Alexey,


First of all thank you for help. You are doing really great job. The workaround that you provided solved part of the problem. But pay attention that font are still different between word and aspose rtf conversion.

I am attaching document.

First section as it was converted by rich text box when i used word (FormatedText property)
Second section as it was converted by rich text box when i used Aspose.
Third section as it was converted by rich text box when i used Aspose with workaround. As you can see text underline now is thiner then in original text although it was fine before workaround.

I talked to my bosses and they ask me to check with you whether it is possible to make conference call between you and them?

Thank you very much,
Stanislav.

Hi Stanislav,

Thank you for additional information. Unfortunately, I cannot reproduce the problem with font on my side. I tested the workaround on the document you have attached earlier and as I can see font is the same as in the original DOC file.

We do not provide technical support over the phone.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/technical-support.html

Best regards,

Hi Alexey,


Unfortunately i found additional problem with rtf converting.

When i am using the same code again

RichTextBox rt = new RichTextBox();
rt.Rtf = getString(BookmarkContent, SaveFormat.Rtf);

picture that was in document disappeared. When i am using Word FormatedText property to copy document content to rich text box it works fine.

Document attached.