编程语言
首页 > 编程语言> > c#-使用DevExpress或Infragistics将HTML或PDF转换为RTF / DOC或HTML / PDF转换为图像

c#-使用DevExpress或Infragistics将HTML或PDF转换为RTF / DOC或HTML / PDF转换为图像

作者:互联网

有一种方法可以使用DevExpress或Infragistics将HTML或PDF转换为RTF / DOC或HTML / PDF转换为图像?

我使用DevExpress尝试过此操作:

string html = new StreamReader(Server.MapPath(@".\teste.htm")).ReadToEnd();

            RichEditControl richEditControl = new RichEditControl();
            string rtf;
            try
            {
                richEditControl.HtmlText = html;
                rtf = richEditControl.RtfText;
            }
            finally
            {
                richEditControl.Dispose();
            }

            StreamWriter sw = new StreamWriter(@"D:\teste.rtf");
            sw.Write(rtf);
            sw.Close();

但我有一个复杂的html内容(表,背景,css等),最终结果不好.

解决方法:

我建议您使用最新的DevExpress版本(这次是10.1.5版).它处理表的能力比以前的更好.

请使用以下代码来避免编码问题(示例中的StreamReader和StreamWriter始终使用Encoding.UTF8编码,这将破坏使用另一种编码存储的任何内容):

    using (RichEditControl richEditControl = new RichEditControl()) {
        richEditControl.LoadDocument(Server.MapPath(@".\teste.htm"), DocumentFormat.Html);
        richEditControl.SaveDocument(@"D:\teste.rtf", DocumentFormat.Rtf);
    }

还要看看richEditControl.Options.Import.Html和richEditControl.Options.Export.Rtf属性,您可能会发现它们在某些情况下很有用.

标签:infragistics,devexpress,asp-net,c,net
来源: https://codeday.me/bug/20191024/1917040.html