Convert HTML or PDF to RTF / DOC or HTML / PDF to image using DevExpress or Infragistics

Is there a way to convert HTML or PDF to RTF / DOC or HTML / PDF to an image using DevExpress or Infragistics?

I tried this using 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();

But I have complex html content (tables, backgrounds, css, etc.) and the end result is not very good ...

+3
source share
2 answers

I suggest you use the latest version of DevExpress (version 10.1.5 this time). It handles tables much better than previous ones.

, , (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, .

+2

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);
    }
}
+3

Source: https://habr.com/ru/post/1752809/


All Articles