private static string GetHtmlFromRTF(string rtfSelection) { IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtfSelection); RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument); return(htmlConverter.Convert()); }
private static string ConvertRtfToHtml(string rtfText) { IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtfText); RtfHtmlConvertSettings settings = new RtfHtmlConvertSettings(); settings.ConvertScope = RtfHtmlConvertScope.Content; RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument, settings); return(htmlConverter.Convert()); } // ConvertRtfToHtml
private string ConvertHmtl(IRtfDocument rtfDocument, RtfVisualImageAdapter imageAdapter) { RtfHtmlConvertSettings htmlConvertSettings = new RtfHtmlConvertSettings(imageAdapter); htmlConvertSettings.Title = "Doc Title " + DateTime.Now.ToString("dd/MM/yyyy"); htmlConvertSettings.ImagesPath = ImagePath; htmlConvertSettings.IsShowHiddenText = IsShowHiddenText; htmlConvertSettings.ConvertVisualHyperlinks = ConvertVisualHyperlinks; RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument, htmlConvertSettings); return(htmlConverter.Convert()); }
/// <summary> /// Do the actual conversion by using a RichTextBox /// </summary> private void Convert() { if (string.IsNullOrEmpty(_rtf)) { _convertedRtf = string.Empty; return; } IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(_rtf); RtfHtmlConverter converter = new RtfHtmlConverter(rtfDocument); _convertedRtf = converter.Convert(); }
} // ToXmlButtonClick // ---------------------------------------------------------------------- private void ToHtmlButtonClick(object sender, EventArgs e) { try { IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(ConversionText); RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument); textBox.Text = htmlConverter.Convert(); } catch (Exception exception) { MessageBox.Show(this, "Error " + exception.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // ToHtmlButtonClick
/// <summary> /// Convert RTF to HTML /// </summary> /// <param name="rtf">The rtf string</param> /// <returns></returns> public static string ConvertRtfToHtml(string rtf) { if (string.IsNullOrEmpty(rtf)) { return(string.Empty); } var rtfDocument = RtfInterpreterTool.BuildDoc(rtf, new RtfInterpreterSettings { IgnoreDuplicatedFonts = true, IgnoreUnknownFonts = true }); var converter = new RtfHtmlConverter(rtfDocument); return(converter.Convert()); }
} // InterpretRtf // ---------------------------------------------------------------------- private string ConvertHmtl(IRtfDocument rtfDocument, IRtfVisualImageAdapter imageAdapter) { string html; try { RtfHtmlConvertSettings htmlConvertSettings = new RtfHtmlConvertSettings(imageAdapter); if (settings.CharacterSet != null) { htmlConvertSettings.CharacterSet = settings.CharacterSet; } htmlConvertSettings.Title = settings.SourceFileNameWithoutExtension; htmlConvertSettings.ImagesPath = settings.ImagesPath; htmlConvertSettings.IsShowHiddenText = settings.ShowHiddenText; htmlConvertSettings.UseNonBreakingSpaces = settings.UseNonBreakingSpaces; if (settings.ConvertScope != RtfHtmlConvertScope.None) { htmlConvertSettings.ConvertScope = settings.ConvertScope; } if (!string.IsNullOrEmpty(settings.StyleSheets)) { string[] styleSheets = settings.StyleSheets.Split(','); htmlConvertSettings.StyleSheetLinks.AddRange(styleSheets); } htmlConvertSettings.ConvertVisualHyperlinks = settings.ConvertVisualHyperlinks; if (!string.IsNullOrEmpty(settings.VisualHyperlinkPattern)) { htmlConvertSettings.VisualHyperlinkPattern = settings.VisualHyperlinkPattern; } htmlConvertSettings.SpecialCharsRepresentation = settings.SpecialCharsRepresentation; RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument, htmlConvertSettings); if (!settings.UseInlineStyles) { htmlConverter.StyleConverter = new RtfEmptyHtmlStyleConverter(); } html = htmlConverter.Convert(); } catch (Exception e) { Console.WriteLine("error while converting to html: " + e.Message); ExitCode = ProgramExitCode.ConvertHtml; return(null); } return(html); } // ConvertHmtl
private static string ConvertHmtl(IRtfDocument rtfDocument, IRtfVisualImageAdapter imageAdapter, RtfHtmlConvertSettings htmlConvertSettings, bool throwOnError = false) { string html = null; try { var htmlConverter = new RtfHtmlConverter(rtfDocument, htmlConvertSettings); html = htmlConverter.Convert(); } catch (Exception e) { if (throwOnError) { ThrowOnUnexpectedExitCode(e); } } return(html); }
public string CovnvertRtftoHtml(string rtf) { const RtfParserListenerLogger parserLogger = null; IRtfGroup rtfStructure = RtfParserTool.Parse(rtf, parserLogger); Assert.IsNotNull(rtfStructure); const RtfInterpreterListenerLogger interpreterLogger = null; RtfTextConverter textConverter = new RtfTextConverter(); IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtfStructure, textConverter, interpreterLogger); RtfHtmlConvertSettings htmlConvertSettings = new RtfHtmlConvertSettings(); htmlConvertSettings.ConvertScope = RtfHtmlConvertScope.Content; RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument); string plainText = htmlConverter.Convert(); plainText = plainText.Replace("@?]e1", "á").Replace("@?]e9", "é").Replace("@?]f3", "ó").Replace("@?]ed", "í").Replace("@?]c1", "á").Replace("@?]f1", "ñ").Replace("@?]fa", "ú"); //aqui reemplazamos para letras con acentos. return(plainText); }
public static void ToHtml(RtfSource source, XmlWriter writer, RtfHtmlWriterSettings settings = null) { settings = settings ?? new RtfHtmlWriterSettings(); var content = ParseRtf(source); // Try to extract encoded html from within the rtf (Outlook likes to do this) if (!BuildHtmlContent(content, writer)) { var intSettings = new RtfInterpreterSettings() { IgnoreDuplicatedFonts = true, IgnoreUnknownFonts = true }; var rtfDocument = RtfInterpreterTool.BuildDoc(content, intSettings); var htmlConvertSettings = new RtfHtmlConvertSettings(settings.ObjectVisitor); htmlConvertSettings.IsShowHiddenText = false; htmlConvertSettings.UseNonBreakingSpaces = false; htmlConvertSettings.ConvertScope = RtfHtmlConvertScope.All; var htmlConverter = new RtfHtmlConverter(rtfDocument, htmlConvertSettings); htmlConverter.Convert(writer); } }
} // ToXmlButtonClick // ---------------------------------------------------------------------- private void ToHtmlButtonClick(object sender, RoutedEventArgs e) { try { TextRange conversionText = ConversionText; using (MemoryStream stream = new MemoryStream()) { conversionText.Save(stream, DataFormats.Rtf); stream.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(stream)) { IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(reader); RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument); textBox.Text = htmlConverter.Convert(); } } } catch (Exception exception) { MessageBox.Show(this, "Error " + exception.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); } } // ToHtmlButtonClick
} // ConvertRtf2Txt // ---------------------------------------------------------------------- public string ConvertRtf2Html(string fileName) { // parser IRtfGroup rtfStructure = ParseRtf(fileName); if (rtfStructure == null) { return(string.Empty); } // interpreter logger RtfInterpreterListenerFileLogger interpreterLogger = null; if (!string.IsNullOrEmpty(InterpreterLogFileName)) { interpreterLogger = new RtfInterpreterListenerFileLogger(InterpreterLogFileName); } // image converter RtfVisualImageAdapter imageAdapter = new RtfVisualImageAdapter(ImageFormat.Jpeg); RtfImageConvertSettings imageConvertSettings = new RtfImageConvertSettings(imageAdapter); imageConvertSettings.ScaleImage = true; // scale images RtfImageConverter imageConverter = new RtfImageConverter(imageConvertSettings); // rtf interpreter RtfInterpreterSettings interpreterSettings = new RtfInterpreterSettings(); IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterSettings, interpreterLogger, imageConverter); // html converter RtfHtmlConvertSettings htmlConvertSettings = new RtfHtmlConvertSettings(); htmlConvertSettings.ConvertScope = RtfHtmlConvertScope.Content; RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument); return(htmlConverter.Convert()); } // ConvertRtf2Html
public static string ConvertRtf2Html(string text, int slideID) { // parser text = text.Replace("\\tab", "$$$$$$$$"); text = text.Replace("li240", "$$$$$$$$$$$$$$$$"); text = text.Replace("li480", "$$$$$$$$$$$"); text = text.Replace("ri480", "$$$$$$$$$$$"); text = text.Replace("li720", "$$$$$$$$$$$$$$"); IRtfGroup rtfStructure = ParseRtf(text); if (rtfStructure == null) { return(string.Empty); } // image converter RtfVisualImageAdapter imageAdapter = new RtfVisualImageAdapter( Path.GetFileNameWithoutExtension(Form1.currentFile) + "\\Slide" + slideID + "_{0}{1}", ImageFormat.Jpeg); RtfImageConvertSettings imageConvertSettings = new RtfImageConvertSettings(imageAdapter); imageConvertSettings.ScaleImage = true; // scale images' string filePath = Path.GetDirectoryName(Form1.currentFile); string folder = Path.GetFileNameWithoutExtension(Form1.currentFile); string directoryPath = filePath + "\\" + folder; //string directoryPath = @"C:\Users\Knwal\Documents\Presentation Tool\Presentation Tool\Preview\"; imageConvertSettings.ImagesPath = directoryPath; RtfImageConverter imageConverter = new RtfImageConverter(imageConvertSettings); Stream st = GenerateStreamFromString(text); RtfInterpreterSettings interpreterSettings = new RtfInterpreterSettings(); IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterSettings, null, imageConverter); // html converter RtfHtmlConvertSettings htmlConvertSettings = new RtfHtmlConvertSettings(imageAdapter); htmlConvertSettings.StyleSheetLinks.Add("default.css"); htmlConvertSettings.ConvertScope = RtfHtmlConvertScope.Content; //htmlConvertSettings.GetImageUrl(); RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument, htmlConvertSettings); string str = htmlConverter.Convert(); str = str.Replace(" ", " "); str = str.Replace("$$$$$$$$", " "); str = str.Replace("$$$", " "); //str= str.Replace("#1#",""); //str = str.Replace("#2#", ""); //str = str.Replace("#3#", ""); //str = str.Replace("#4#", ""); //str = str.Replace("#5#", ""); //str = str.Replace("#6#", ""); //str = str.Replace("#7#", ""); //str = str.Replace("#8#", ""); //str = str.Replace("#9#", ""); return(str); } // ConvertRtf2Html