2010-07-02 177 views
3

使用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等),最终的结果并不好......

回答

2

我建议你使用最新的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属性,您可能会发现它们在某些情况下很有用。

3

的HTML内容转换成图片或PDF您可以使用下面的代码:

using (RichEditControl richEditControl = new RichEditControl()) { 
    richEditControl.LoadDocument(Server.MapPath(@".\teste.htm"), DocumentFormat.Html); 
    using (PrintingSystem ps = new PrintingSystem()) { 
     PrintableComponentLink pcl = new PrintableComponentLink(ps); 
     pcl.Component = richEditControl; 
     pcl.CreateDocument(); 
     //pcl.PrintingSystem.ExportToPdf("teste.pdf"); 
     pcl.PrintingSystem.ExportToImage("teste.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
    } 
} 
+0

你好DevExpress的团队!我们有DevExpress版本9.3,PDF,JPG或RTF的结果不好。 html源代码非常复杂,很多表格和CSS。但是,坦克的提示! – Fabio 2010-07-07 18:59:07

+0

自10.1版以来,XtraRichEdit中引入了表支持。版本9.3只能按段落顺序读取表格内容。这就是为什么当用9.3转换复杂的html时你无法取得好的结果。 – 2010-07-07 20:49:17

相关问题