Пример #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;
                    imageConvertSettings.ScaleImage = !settings.UnscaledImages;
                    if ( settings.ExtendedImageScale )
                    {
                        imageConvertSettings.ScaleExtension = 0.5f;
                    }
                    imageConverter = new RtfImageConverter( imageConvertSettings );
                }

                // rtf interpreter
                RtfInterpreterSettings interpreterSettings = new RtfInterpreterSettings();
                interpreterSettings.IgnoreDuplicatedFonts = settings.IgnoreDuplicatedFonts;
                interpreterSettings.IgnoreUnknownFonts = settings.IgnoreUnknownFonts;

                // 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;
        }
Пример #2
0
        // ----------------------------------------------------------------------
        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;
                    imageConvertSettings.ScaleImage = !settings.UnscaledImages;
                    if ( settings.ExtendedImageScale )
                    {
                        imageConvertSettings.ScaleExtension = 0.5f;
                    }
                    imageConverter = new RtfImageConverter( imageConvertSettings );
                }

                // rtf interpreter
                RtfInterpreterSettings interpreterSettings = new RtfInterpreterSettings();
                interpreterSettings.IgnoreDuplicatedFonts = settings.IgnoreDuplicatedFonts;
                interpreterSettings.IgnoreUnknownFonts = settings.IgnoreUnknownFonts;

                // interpret the rtf structure using the extractors
                rtfDocument = RtfInterpreterTool.BuildDoc( rtfStructure, interpreterSettings, 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;
        }