C# 使用DevExpress或Infragistics将HTML或PDF转换为RTF/DOC,或将HTML/PDF转换为图像
有一种方法可以使用DevExpress或Infragistics将HTML或PDF转换为RTF/DOC,或将HTML/PDF转换为图像 我使用DevExpress尝试了以下操作:C# 使用DevExpress或Infragistics将HTML或PDF转换为RTF/DOC,或将HTML/PDF转换为图像,c#,.net,asp.net,devexpress,infragistics,C#,.net,Asp.net,Devexpress,Infragistics,有一种方法可以使用DevExpress或Infragistics将HTML或PDF转换为RTF/DOC,或将HTML/PDF转换为图像 我使用DevExpress尝试了以下操作: string html = new StreamReader(Server.MapPath(@".\teste.htm")).ReadToEnd(); RichEditControl richEditControl = new RichEditControl(); st
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等),最终结果不好…我建议您使用最新的develxpress版本(这次是10.1.5版)。它比以前的表处理得好得多 请使用以下代码避免编码问题(示例中的StreamReader和StreamWriter始终使用encoding.UTF8编码,这将损坏使用其他编码存储的任何内容):
还可以查看richEditControl.Options.Import.Html和richEditControl.Options.Export.Rtf属性,您可能会发现它们在某些情况下很有用。要将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);
}
}
你好,DevExpress团队!我们有DevExpress版本9.3,在PDF、JPG或RTF中的结果不好。html源代码非常复杂,有许多表格和CSS。但是,为了小费!自10.1版以来,XtraRichEdit中引入了表支持。版本9.3只能按段落顺序读取表格内容。这就是为什么在使用9.3转换复杂html时无法获得良好结果的原因。
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);
}
}