public void AddParserListener(IRtfParserListener listener) { if (listener == null) { throw new ArgumentNullException(nameof(listener)); } if (_listeners == null) { _listeners = new ArrayList(); } if (!_listeners.Contains(listener)) { _listeners.Add(listener); } } // AddParserListener
// ---------------------------------------------------------------------- public void AddParserListener( IRtfParserListener listener ) { if ( listener == null ) { throw new ArgumentNullException( "listener" ); } if ( listeners == null ) { listeners = new ArrayList(); } if ( !listeners.Contains( listener ) ) { listeners.Add( listener ); } }
} // IgnoreContentAfterRootGroup // ---------------------------------------------------------------------- public void AddParserListener(IRtfParserListener listener) { if (listener == null) { throw new ArgumentNullException("listener"); } if (this.listeners == null) { this.listeners = new ArrayList(); } if (!this.listeners.Contains(listener)) { this.listeners.Add(listener); } } // AddParserListener
} // AddParserListener public void RemoveParserListener(IRtfParserListener listener) { if (listener == null) { throw new ArgumentNullException(nameof(listener)); } if (_listeners != null) { if (_listeners.Contains(listener)) { _listeners.Remove(listener); } if (_listeners.Count == 0) { _listeners = null; } } } // RemoveParserListener
} // AddParserListener // ---------------------------------------------------------------------- public void RemoveParserListener( IRtfParserListener listener ) { if ( listener == null ) { throw new ArgumentNullException( "listener" ); } if ( this.listeners != null ) { if ( this.listeners.Contains( listener ) ) { this.listeners.Remove( listener ); } if ( this.listeners.Count == 0 ) { this.listeners = null; } } } // RemoveParserListener
public static string RtfToHtml(this string str, RtfHtmlConvertSettings htmlConvertSettings, bool throwOnError = false, IRtfParserListener listener = null, string destinationDirectory = null, RtfVisualImageAdapter imageAdapter = null, string imageAdapterLogFile = null, RtfImageConvertSettings imageConvertSettings = null) { IRtfGroup rtfStructure; IRtfDocument rtfDocument = null; try { using (var stream = str.ToStream()) { // parse the rtf structure var structureBuilder = new RtfParserListenerStructureBuilder(); var parser = new RtfParser(structureBuilder); DirectoryInfo destination; if (destinationDirectory != null) { destination = new DirectoryInfo(destinationDirectory); } parser.IgnoreContentAfterRootGroup = true; // support WordPad documents if (listener != null) { parser.AddParserListener(listener); } parser.Parse(new RtfSource(stream)); rtfStructure = structureBuilder.StructureRoot; ThrowOnUnexpectedExitCode(); rtfDocument = InterpretRtf(rtfStructure, imageAdapter, imageAdapterLogFile, imageConvertSettings, throwOnError); if (throwOnError) { ThrowOnUnexpectedExitCode(); } // convert to hmtl string html = ConvertHmtl(rtfDocument, imageAdapter, htmlConvertSettings, throwOnError); if (throwOnError) { ThrowOnUnexpectedExitCode(); } return(html); } } catch (Exception e) { Debug.WriteLine("RtfToHtml parser failed with error: {0}", e.Message); } return(null); }
public RtfParser(TextReader reader, IRtfParserListener listener) { _reader = reader; _listener = listener; }