Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Wed Mar 13, 2013 4:32 pm

Hi!

I've got a problem converting RTF code to HTML code (with streams, without files). The HTML output code isn't correct.

Code: Select all
Spire.Doc.Document doc = new Spire.Doc.Document();

System.Text.ASCIIEncoding asc = new System.Text.ASCIIEncoding();
byte[] bArrRTF = asc.GetBytes(richTextBox1.Rtf);

System.IO.MemoryStream msRTF = new System.IO.MemoryStream(bArrRTF);

doc.LoadFromStream(msRTF, Spire.Doc.FileFormat.Rtf);

System.IO.MemoryStream msHTML = new System.IO.MemoryStream();
           
doc.HtmlExportOptions.CssStyleSheetType = Spire.Doc.CssStyleSheetType.Internal;
doc.SaveToStream(msHTML, Spire.Doc.FileFormat.Html);

System.Text.UTF8Encoding utf = new UTF8Encoding();

string strHTMLCode = utf.GetString(msHTML.ToArray());


The html output contains "\r\n" instead of "<br>" (for example).
Pictures and font colors are missing.

What could be wrong?

Thanks in advance :)

ischmidt
 
Posts: 6
Joined: Wed Mar 13, 2013 12:52 pm

Thu Mar 14, 2013 7:01 am

Dear ischmidt,

Thanks for your inquiry.
Please try to save bArrRTF to a .bin file and provide us the .bin file. It will help us to reproduce and solve this issue soon.
Thank you in advance!
Code: Select all
 System.Text.UTF8Encoding asc = new System.Text.UTF8Encoding();
 byte[] bArrRTF = asc.GetBytes(richTextBox1.Rtf);
 System.IO.File.WriteAllBytes("sample.bin",bArrRTF);


Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2284
Joined: Wed Jun 27, 2012 8:50 am

Thu Mar 14, 2013 3:19 pm

I've attached a bin file.

I hope this file will help to solve the problem.

Thanks for your efforts,
I.Schmidt
You do not have the required permissions to view the files attached to this post.

ischmidt
 
Posts: 6
Joined: Wed Mar 13, 2013 12:52 pm

Fri Mar 15, 2013 3:13 am

Dear I.Schmidt,

Thanks for your file.
We had done the test with your rtf data, but we didn't reproduce this issue you met. The outputted html don't contain "\r\n" instead of "<br>". The outputted html don't miss the pictures and font original colors. We attached two screenshots and the outputted html. One screenshot shows the showing of your rtf file, the other shows the showing of the outputted html.
Our tested version is Spire.Doc Pack (Hot Fix) Version:4.6.28( http://www.e-iceblue.com/Download/download-word-for-net-now.html). The tested dlls are from spire.doc_4.6.28\ BIN\ NET4.0. Please try to test spire.doc_4.6.28 with your file.
If you still have the issue or we miss some thing, please tell us.
Have a nice day!

Best Regards,
Amy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

amy.zhao
 
Posts: 2284
Joined: Wed Jun 27, 2012 8:50 am

Fri Mar 15, 2013 7:50 am

Thanks for testing :)

I've downloaded the hot fix and linked it to my project. But I've still the same problem.
I've attached the generated html code and a screenshot.

If I'm using the method "SaveToFile" it works almost. Styles are OK. The image is missing.
But if I'm using the method "SaveToStream", it looks like the attached image...



edit:
Maybe it's important: I copy content (via clipboard) from an application (word for example) into the RichTextBox.
You do not have the required permissions to view the files attached to this post.

ischmidt
 
Posts: 6
Joined: Wed Mar 13, 2013 12:52 pm

Fri Mar 15, 2013 8:42 am

Dear I.Schmidt,

Thanks for your feedback.
We did the test with the method "SaveToFile" and the method "SaveToStream" separately, but still didn't reproduce your problem.
We attached our test code below. Please kindly note that the outputted image and the outputted html files must be saved to the same path.
Code: Select all
       using (MemoryStream rtfStream = new MemoryStream(File.ReadAllBytes(@"..\..\sample.bin")))
            {
                Document document = new Document();
                document.LoadFromStream(rtfStream, FileFormat.Rtf);
                document.HtmlExportOptions.CssStyleSheetType = Spire.Doc.CssStyleSheetType.Internal;
                document.HtmlExportOptions.ImagesPath = "C:\\output";

               //use the method "SaveToFile"
                document.SaveToFile("C:\\output\\out.html",FileFormat.Html);
                using (MemoryStream htmlStream = new MemoryStream())
                {
                   //use the method "SaveToStream"
                    document.SaveToStream(htmlStream, FileFormat.Html);
                    File.WriteAllBytes("C:\\output\\output.html", htmlStream.ToArray());
                }
            }


Please test the code above. If you still have the problem, please tell us.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2284
Joined: Wed Jun 27, 2012 8:50 am

Mon Mar 18, 2013 8:47 am

I've tested your code. It works. The html output is correct.
But unfortunately I don't want to create a html file. I just need the code.

If I convert a html stream to a string, the string contains escape sequences (\r\n and \"). I think that is my problem. Is there any way to get the code without escape sequences?

Best regards,
I. Schmidt

ischmidt
 
Posts: 6
Joined: Wed Mar 13, 2013 12:52 pm

Tue Mar 19, 2013 2:47 am

Dear I. Schmidt,

Thanks for your feedback.
Please refer to the code snippet below to get the string. We have done the test , and the outputted string is correct.
We attacted our outputted file.
Code: Select all
 using (MemoryStream htmlStream = new MemoryStream())
                {
                    document.SaveToStream(htmlStream, FileFormat.Html);
                    File.WriteAllBytes("output.txt", htmlStream.ToArray());
                 
                }


If you still have this issue, please tell us.

Have a nice day!

Best Regards,
Amy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

amy.zhao
 
Posts: 2284
Joined: Wed Jun 27, 2012 8:50 am

Thu Mar 21, 2013 10:13 am

Dear Schmidt,

Does our previous code solve your problem?
Please give you a feedback on this issue at your early convenience.
Thank you!
If you have other any problem, please tell us.

Best regards,
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Return to Spire.Doc

cron