Inheritance: RtfInterpreterListenerBase, IDisposable
Esempio n. 1
0
        // ----------------------------------------------------------------------
        private string InterpretRtf( IRtfGroup rtfStructure )
        {
            string text = null;

            RtfInterpreterListenerFileLogger interpreterLogger = null;
            try
            {
                // logger
                if ( settings.LogInterpreter )
                {
                    string logFileName = settings.BuildDestinationFileName(
                        settings.LogDirectory,
                        RtfInterpreterListenerFileLogger.DefaultLogFileExtension );
                    interpreterLogger = new RtfInterpreterListenerFileLogger( logFileName );
                }

                // text converter
                RtfTextConverter textConverter = null;
                if ( settings.SaveText )
                {
                    RtfTextConvertSettings textConvertSettings = new RtfTextConvertSettings();
                    textConvertSettings.IsShowHiddenText = settings.ShowHiddenText;
                    textConverter = new RtfTextConverter( textConvertSettings );
                }

                // image converter
                RtfImageConverter imageConverter = null;
                if ( settings.SaveImage )
                {
                    RtfVisualImageAdapter imageAdapter = new RtfVisualImageAdapter(
                        settings.ImageFileNamePattern,
                        settings.ImageFormat );
                    RtfImageConvertSettings imageConvertSettings = new RtfImageConvertSettings( imageAdapter );
                    imageConvertSettings.ImagesPath = settings.DestinationDirectory;
                    imageConvertSettings.ScaleImage = settings.ScaleImage;
                    imageConvertSettings.BackgroundColor = settings.ImageBackgroundColor;
                    if ( settings.ExtendedImageScale )
                    {
                        imageConvertSettings.ScaleExtension = 0.5f;
                    }
                    imageConverter = new RtfImageConverter( imageConvertSettings );
                }

                // rtf parser
                // interpret the rtf structure using the extractors
                RtfInterpreterTool.Interpret( rtfStructure, interpreterLogger, textConverter, imageConverter );

                // get the resulting text
                if ( textConverter != null )
                {
                    text = textConverter.PlainText;
                }
            }
            catch ( Exception e )
            {
                if ( interpreterLogger != null )
                {
                    interpreterLogger.Dispose();
                }

                Console.WriteLine( "error while interpreting rtf: " + e.Message );
                ExitCode = ProgramExitCode.InterpretRtf;
                return null;
            }

            return text;
        }
Esempio n. 2
0
        // ----------------------------------------------------------------------
        private IRtfDocument InterpretRtf( IRtfGroup rtfStructure )
        {
            IRtfDocument rtfDocument;
            RtfInterpreterListenerFileLogger interpreterLogger = null;
            try
            {
                // logger
                if ( settings.LogInterpreter )
                {
                    string logFileName = settings.BuildDestinationFileName(
                        settings.LogDirectory,
                        RtfInterpreterListenerFileLogger.DefaultLogFileExtension );
                    interpreterLogger = new RtfInterpreterListenerFileLogger( logFileName );
                }

                // rtf parser
                // interpret the rtf structure using the extractors
                rtfDocument = RtfInterpreterTool.BuildDoc( rtfStructure, interpreterLogger );
            }
            catch ( Exception e )
            {
                if ( interpreterLogger != null )
                {
                    interpreterLogger.Dispose();
                }

                Console.WriteLine( "error while interpreting rtf: " + e.Message );
                ExitCode = ProgramExitCode.InterpretRtf;
                return null;
            }

            return rtfDocument;
        }
 // ----------------------------------------------------------------------
 static void RtfSympleInterpreter()
 {
     RtfInterpreterListenerFileLogger logger = new RtfInterpreterListenerFileLogger( @"c:\temp\RtfInterpreter.log" );
     IRtfDocument document = RtfInterpreterTool.BuildDoc( @"{\rtf1foobar}", logger );
     RtfWriteDocument( document );
 }
        // ----------------------------------------------------------------------
        private IRtfDocument InterpretRtf( IRtfGroup rtfStructure, IRtfVisualImageAdapter imageAdapter )
        {
            IRtfDocument rtfDocument;
            RtfInterpreterListenerFileLogger interpreterLogger = null;
            try
            {
                // logger
                if ( settings.LogInterpreter )
                {
                    string logFileName = settings.BuildDestinationFileName(
                        settings.LogDirectory,
                        RtfInterpreterListenerFileLogger.DefaultLogFileExtension );
                    interpreterLogger = new RtfInterpreterListenerFileLogger( logFileName );
                }

                // image converter
                RtfImageConverter imageConverter = null;
                if ( settings.SaveImage )
                {
                    RtfImageConvertSettings imageConvertSettings = new RtfImageConvertSettings( imageAdapter );
                    imageConvertSettings.ImagesPath = settings.DestinationDirectory;
                    imageConvertSettings.BackgroundColor = settings.ImageBackgroundColor;
                    if ( settings.ExtendedImageScale )
                    {
                        imageConvertSettings.ScaleExtension = 0.5f;
                    }
                    imageConverter = new RtfImageConverter( imageConvertSettings );
                }

                // rtf parser
                // interpret the rtf structure using the extractors
                rtfDocument = RtfInterpreterTool.BuildDoc( rtfStructure, interpreterLogger, imageConverter );

            }
            catch ( Exception e )
            {
                if ( interpreterLogger != null )
                {
                    interpreterLogger.Dispose();
                }

                Console.WriteLine( "error while interpreting rtf: " + e.Message );
                ExitCode = ProgramExitCode.InterpretRtf;
                return null;
            }

            return rtfDocument;
        }