Esempio n. 1
0
        }         // RtfDumpElement

        // ----------------------------------------------------------------------
        static void RtfSympleInterpreter()
        {
            RtfInterpreterListenerFileLogger logger = new RtfInterpreterListenerFileLogger(@"c:\temp\RtfInterpreter.log");
            IRtfDocument document = RtfInterpreterTool.BuildDoc(@"{\rtf1foobar}", logger);

            RtfWriteDocument(document);
        }         // RtfSympleInterpreter
Esempio n. 2
0
        // ----------------------------------------------------------------------
        public string ConvertRtf2Txt(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);
            }

            // text converter
            RtfTextConvertSettings textConvertSettings = new RtfTextConvertSettings();

            textConvertSettings.BulletText = "-";
            RtfTextConverter textConverter = new RtfTextConverter(textConvertSettings);

            // text interpreter
            RtfInterpreterTool.Interpret(rtfStructure, interpreterLogger, textConverter);
            return(textConverter.PlainText);
        }         // ConvertRtf2Txt
Esempio n. 3
0
        }         // EnsureDestinationDirectory

        // ----------------------------------------------------------------------
        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);
        }         // InterpretRtf
Esempio n. 4
0
        }         // EnsureDestinationDirectory

        // ----------------------------------------------------------------------
        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);
        }         // InterpretRtf
Esempio n. 5
0
        }         // EnsureDestinationDirectory

        // ----------------------------------------------------------------------
        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();
                }

                MessageBox(IntPtr.Zero, "Error while interpreting RTF:\n" + e.Message, "Itenso.Rtf2Html", 0x010000);
                ExitCode = ProgramExitCode.InterpretRtf;
                return(null);
            }

            return(rtfDocument);
        }         // InterpretRtf
Esempio n. 6
0
        private static IRtfDocument InterpretRtf(IRtfGroup rtfStructure, IRtfVisualImageAdapter imageAdapter, string imageAdapterLogFile = null, RtfImageConvertSettings imageConvertSettings = null, bool throwOnError = false)
        {
            IRtfDocument rtfDocument;
            RtfInterpreterListenerFileLogger interpreterLogger = null;

            try
            {
                // logger
                if (imageAdapterLogFile != null)
                {
                    interpreterLogger = new RtfInterpreterListenerFileLogger(imageAdapterLogFile);
                }

                // image converter
                RtfImageConverter imageConverter = null;

                if (imageConvertSettings != null)
                {
                    imageConverter = new RtfImageConverter(imageConvertSettings);
                }

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

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

                if (throwOnError)
                {
                    ThrowOnUnexpectedExitCode(e);
                }

                return(null);
            }

            return(rtfDocument);
        }
Esempio n. 7
0
        }         // 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
Esempio n. 8
0
        }         // EnsureDestinationDirectory

        // ----------------------------------------------------------------------
        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);
        }         // InterpretRtf