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

There is a way do convert HTML or PDF to RTF/DOC or HTML/PDF to 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 a complex html content (tables, backgrounds, css etc) and the final result is not good...

Answers


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

Please use the following code to avoid encoding issues (StreamReader and StreamWriter in your sample always use Encoding.UTF8 encoding, this will corrupt any content stored with another encoding):

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

Also take a look at the richEditControl.Options.Import.Html and richEditControl.Options.Export.Rtf properties, you may find them useful for some cases.


To convert Html content into image or Pdf you may use the following code:

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

Need Your Help

How to convert spring security xml configuration to java configuration?

spring spring-mvc spring-security

I'm trying to convert the below xml to java configuration, but confused with alias argument in the sec:authentication-manager tag. I have worked on the partial part of java configuration and will

nginx req limit & fail2ban & cloudflare large attacks

php security nginx

I started to use as the topic says nginx with req limit + fail2ban + cloudflare. If someone exceeds the requests on any php file the ip gets blocked over the cloudflare api in the "ip firewall" on