Inheritance: Itenso.Rtf.Support.RtfVisualVisitorBase
コード例 #1
0
ファイル: RtfWindow.xaml.cs プロジェクト: haimon74/KanNaim
		} // ToTextButtonClick

		// ----------------------------------------------------------------------
		private void ToXmlButtonClick( 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 );

						XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
						xmlWriterSettings.Indent = true;
						xmlWriterSettings.IndentChars = ( "  " );
						StringBuilder sb = new StringBuilder();
						using ( XmlWriter writer = XmlWriter.Create( sb, xmlWriterSettings ) )
						{
							RtfXmlConverter xmlConverter = new RtfXmlConverter( rtfDocument, writer );
							xmlConverter.Convert();
							writer.Flush();
							this.textBox.Text = sb.ToString();
						}
					}
				}
			}
			catch ( Exception exception )
			{
				MessageBox.Show( this, "Error " + exception.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error );
			}
		} // ToXmlButtonClick
コード例 #2
0
        // ----------------------------------------------------------------------
        private void ToXmlButtonClick( object sender, EventArgs e )
        {
            try
            {
                IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc( ConversionText );

                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent = true;
                xmlWriterSettings.IndentChars = ( "  " );
                StringBuilder sb = new StringBuilder();
                using ( XmlWriter writer = XmlWriter.Create( sb, xmlWriterSettings ) )
                {
                    RtfXmlConverter xmlConverter = new RtfXmlConverter( rtfDocument, writer );
                    xmlConverter.Convert();
                    writer.Flush();
                    textBox.Text = sb.ToString();
                }
            }
            catch ( Exception exception )
            {
                MessageBox.Show( this, "Error " + exception.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error );
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: CodeFork/RtfConverter
        // ----------------------------------------------------------------------
        private void ConvertXml( IRtfDocument rtfDocument )
        {
            try
            {
                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent = true;
                xmlWriterSettings.IndentChars = ( "  " );
                xmlWriterSettings.Encoding = settings.Encoding;

                string fileName = settings.BuildDestinationFileName( null, RtfXmlConverter.DefaultXmlFileExtension );
                using ( XmlWriter writer = XmlWriter.Create( fileName, xmlWriterSettings ) )
                {
                    RtfXmlConvertSettings xmlConvertSettings = new RtfXmlConvertSettings();
                    xmlConvertSettings.Prefix = settings.XmlPrefix;
                    xmlConvertSettings.Ns = settings.XmlNamespace;
                    xmlConvertSettings.IsShowHiddenText = settings.ShowHiddenText;
                    RtfXmlConverter xmlConverter = new RtfXmlConverter( rtfDocument, writer, xmlConvertSettings );
                    xmlConverter.Convert();
                    writer.Flush();
                }
            }
            catch ( Exception e )
            {
                Console.WriteLine( "error while converting to xml: " + e.Message );
                ExitCode = ProgramExitCode.ConvertXml;
            }
        }