示例#1
0
        static void Main(string[] args)
        {
            string inpFile = @"..\..\example.rtf";
            string outFile = @"Title.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            // Set document title, <title>...</title>
            r.TextStyle.Title = "Here is the custom TITLE!";

            // Set the folder to store images
            r.ImageStyle.ImageFolder = Path.GetDirectoryName(Path.GetFullPath(outFile));

            try
            {
                r.OpenRtf(inpFile);
                r.ToHtml(outFile);

                // Open the results for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            // We'll use the files only for the demonstration,
            // the whole conversion will be done using MemoryStream.
            string inpFile = @"..\..\example.rtf";
            string outFile = @"Result.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            // Specify some properties for output HTML document.
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5;
            r.Encoding     = SautinSoft.RtfToHtml.eEncoding.UTF_8;

            // Imagefolder must already exist.
            r.ImageStyle.ImageFolder = System.Environment.CurrentDirectory;

            // Subfolder for images will be created by the component.
            r.ImageStyle.ImageSubFolder = "image.files";

            // A template name for images.
            r.ImageStyle.ImageFileName = "picture";

            // false - store images as files on HDD,
            // true - store images inside HTML document using base64.
            r.ImageStyle.IncludeImageInHtml = false;

            try
            {
                using (FileStream rtfFileStream = new FileStream(inpFile, FileMode.Open))
                {
                    r.OpenRtf(rtfFileStream);
                    using (MemoryStream htmlMemoryStream = new MemoryStream())
                    {
                        // Here we've got the HTML document as an array of bytes.
                        r.ToHtml(htmlMemoryStream);

                        // Save our HTML into file and open it for the demonstration purposes.
                        File.WriteAllBytes(outFile, htmlMemoryStream.ToArray());
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                        {
                            UseShellExecute = true
                        });
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            string inpFile          = @"..\..\example.rtf";
            string outFileInlineCSS = @"Inline CSS.html";
            string outFileClassCSS  = @"Class CSS.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            // Skip images.
            r.ImageStyle.PreserveImages = false;

            try
            {
                r.OpenRtf(inpFile);

                // Specify the title.
                r.TextStyle.Title = "Inline CSS";

                // Generate inline CSS.
                r.TextStyle.InlineCSS = true;

                // Convert to HTML.
                r.ToHtml(outFileInlineCSS);

                // Specify the title.
                r.TextStyle.Title = "Class CSS";

                // Store CSS using the attribute "class".
                r.TextStyle.InlineCSS      = false;
                r.TextStyle.StyleName      = "style";
                r.TextStyle.StartCSSNumber = 100;

                // Convert to HTML.
                r.ToHtml(outFileClassCSS);

                // Open the results for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileInlineCSS)
                {
                    UseShellExecute = true
                });
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileClassCSS)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            string inpFile = Path.GetFullPath(@"..\..\example.rtf");
            string outFileOriginalFonts = @"Original Fonts.html";
            string outFileSingleFont    = @"Single Font.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            // Skip images.
            r.ImageStyle.PreserveImages = false;

            try
            {
                r.OpenRtf(inpFile);

                // Specify the title.
                r.TextStyle.Title = "Original Fonts";

                // Convert to HTML.
                r.ToHtml(outFileOriginalFonts);

                // Specify the title.
                r.TextStyle.Title = "Single Font";

                // Set single font family, size and color.
                r.TextStyle.FontColor.SetRGB(6, 85, 53);
                r.TextStyle.FontFace = "Verdana";
                r.TextStyle.FontSize = 18;

                // Convert to HTML.
                r.ToHtml(outFileSingleFont);

                // Open the results for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileOriginalFonts)
                {
                    UseShellExecute = true
                });
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileSingleFont)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            // Read our RTF document as string.
            string inpFile   = @"..\..\example.rtf";
            string rtfString = File.ReadAllText(inpFile);

            string outFile = @"Result.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            // Specify some properties for output HTML document.
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5;
            r.Encoding     = SautinSoft.RtfToHtml.eEncoding.UTF_8;

            // Imagefolder must already exist.
            r.ImageStyle.ImageFolder = System.Environment.CurrentDirectory;

            // Subfolder for images will be created by the component.
            r.ImageStyle.ImageSubFolder = "image.files";

            // A template name for images.
            r.ImageStyle.ImageFileName = "picture";

            // false - store images as files on HDD,
            // true - store images inside HTML document using base64.
            r.ImageStyle.IncludeImageInHtml = false;

            try
            {
                r.OpenRtf(rtfString);
                r.ToHtml(outFile);

                // Open the result for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            string inpFile      = @"..\..\unicode.rtf";
            string outFileNCR   = @"NCR.html";
            string outFileNoNCR = @"Without NCR.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            try
            {
                r.OpenRtf(inpFile);

                // Set to use NCR (Numeric Character Reference), in other words
                // write characters as &#XXXX;
                r.UseNumericCharacterReference = true;
                r.TextStyle.Title = "NCR";
                r.ToHtml(outFileNCR);

                // Don't use NCR, write characters us Unicode (utf-8), like a: på taket är en figur.
                r.UseNumericCharacterReference = false;
                r.TextStyle.Title = "Without NCR";
                r.ToHtml(outFileNoNCR);

                // Open the results for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileNCR)
                {
                    UseShellExecute = true
                });
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileNoNCR)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            string inpFile            = @"..\..\links.rtf";
            string outFileNotDetected = @"detect false.html";
            string outFileDetected    = @"detect true.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            try
            {
                r.OpenRtf(inpFile);

                // Don't detect hyperlinks from text, convert only real hyperlinks.
                r.TextStyle.HyperlinkDetect = false;
                r.TextStyle.Title           = "HyperlinkDetect = false";
                r.ToHtml(outFileNotDetected);

                // Automatically detect hyperlinks from text.
                r.TextStyle.HyperlinkDetect = true;
                r.TextStyle.HyperlinkTarget = SautinSoft.RtfToHtml.eHyperlinkTarget.Blank;
                r.TextStyle.Title           = "HyperlinkDetect = true";
                r.ToHtml(outFileDetected);

                // Open the results for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileNotDetected)
                {
                    UseShellExecute = true
                });
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileDetected)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            string inpFile       = @"..\..\two paragraphs.rtf";
            string outFileTagP   = @"p.html";
            string outFileTagDiv = @"div.html";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            try
            {
                r.OpenRtf(inpFile);

                // Set tag <p>...</p> for the paragraphs.
                r.TagStyle.ParagraphTag = SautinSoft.RtfToHtml.eTags.p;
                r.TextStyle.Title       = "P tag";
                r.ToHtml(outFileTagP);

                // Set tag <div>...</div> for the paragraphs.
                r.TagStyle.ParagraphTag = SautinSoft.RtfToHtml.eTags.div;
                r.TextStyle.Title       = "DIV tag";
                r.ToHtml(outFileTagDiv);

                // Open the results for demonstration purposes.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileTagP)
                {
                    UseShellExecute = true
                });
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileTagDiv)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            string inpFile = @"..\..\images.rtf";

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

            try
            {
                r.OpenRtf(inpFile);

                // Case "1" - store image as separate *.png files in subfolder "filename.images".
                string outFile = Path.Combine(Directory.GetCurrentDirectory(), "case 1.html");

                // The image folder must be already existed.
                r.ImageStyle.ImageFolder = Path.GetDirectoryName(outFile);

                // If subfolder is not exist, it will be created by the component.
                r.ImageStyle.ImageSubFolder = "case 1.images";

                // A template name for images.
                r.ImageStyle.ImageFileName = "picture";

                // Don't embed images inside HTML document.
                r.ImageStyle.IncludeImageInHtml = false;

                // Assume, that we already have 100 images in the subfolder, let's start to name images from 101.
                r.ImageStyle.ImageNumStart = 101;
                r.ImageStyle.ImagesFormat  = SautinSoft.RtfToHtml.eImageFormat.Png;

                // Case "1" - convert to HTML and Show the result.
                r.TextStyle.Title = "Case 1 - PNG files";
                r.ToHtml(outFile);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });

                // Case "2" - store image as separate *.jpeg files in subfolder "filename.images".
                outFile = Path.Combine(Directory.GetCurrentDirectory(), "case 2.html");
                r.ImageStyle.ImagesFormat = SautinSoft.RtfToHtml.eImageFormat.Jpg;
                r.TextStyle.Title         = "Case 2 - JPEG files";
                r.ToHtml(outFile);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });

                // Case "3" - skip images.
                outFile = Path.Combine(Directory.GetCurrentDirectory(), "case 3.html");
                r.ImageStyle.PreserveImages = false;
                r.TextStyle.Title           = "Case 3 - No images";
                r.ToHtml(outFile);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });

                // Case "4" - embed images inside HTML document using base64.
                outFile = Path.Combine(Directory.GetCurrentDirectory(), "case 4.html");
                r.ImageStyle.PreserveImages     = true;
                r.ImageStyle.IncludeImageInHtml = true;
                r.TextStyle.Title = "Case 4 - Embedded images";
                r.ToHtml(outFile);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            string rtfFile = Path.GetFullPath(@"..\..\images.rtf");

            // 1. Convert RTF to HTML and place all images to list
            string rtfString = File.ReadAllText(rtfFile);

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
            r.ImageStyle.IncludeImageInHtml = false;
            List <SautinSoft.RtfToHtml.SautinImage> imageList = new List <SautinSoft.RtfToHtml.SautinImage>();

            // 2. After launching this method we'll get our RTF document in HTML format
            // and list of all images.
            r.OpenRtf(rtfString);
            string htmlString = String.Empty;

            r.ToHtml(out htmlString, imageList);

            // 3. Create HTML email
            string from    = "*****@*****.**";
            string to      = "*****@*****.**";
            string subject = "This is a testing email from Bob to John using SmtpClient";

            MailMessage emailMessage = new MailMessage();

            emailMessage.From = new MailAddress(from);
            emailMessage.To.Add(to);
            emailMessage.Subject = subject.Replace("\r\n", "");

            // 4. Attach images to email
            System.Net.Mail.AlternateView altView = AlternateView.CreateAlternateViewFromString(htmlString, null, "text/html");

            foreach (SautinSoft.RtfToHtml.SautinImage simg in imageList)
            {
                if (simg.Img != null)
                {
                    LinkedResource         lr = null;
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    simg.Img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    if (ms != null && ms.Position > 0)
                    {
                        ms.Position = 0;
                    }
                    lr           = new LinkedResource(ms);
                    lr.ContentId = simg.Cid;
                    altView.LinkedResources.Add(lr);
                }
            }
            emailMessage.AlternateViews.Add(altView);

            // 5. Send the message using email account
            string userName     = "******";
            string userPassword = "******";

            SmtpClient client = new SmtpClient();

            client.Port           = 25;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            //client.UseDefaultCredentials = false;

            // Some smtp servers doesn't require credentials, therefore
            // you may set: client.UseDefaultCredentials = false;
            // and remove the line: client.Credentials = new NetworkCredential(userName, userPassword);

            client.Credentials = new NetworkCredential(userName, userPassword);
            client.Host        = "smtpout.bobsite.com";

            // In the real example in case of the correct host, uncomment the line below:
            //client.Send(emailMessage);
            Console.WriteLine("The message has been sent!");
            Console.ReadKey();
        }