Наследование: Itenso.Rtf.Support.RtfVisualVisitorBase
        public bool ConvertCourseFields()
        {
            IRtfDocument crsPhilosophy;
            IRtfDocument crsRationale;
            IRtfDocument crsDescription;
            RtfHtmlConverter htmlConverter;

                foreach (Course crs in _Courses)
                {
                    crs.Grade = ConvertCourseGrade(crs.Grade);

                    try
                    {
                        //Convert Philosophy
                        if (crs.Philosophy != "" && crs.Philosophy != null)
                        {
                            crsPhilosophy = RtfInterpreterTool.BuildDoc(crs.Philosophy);
                            htmlConverter = new RtfHtmlConverter(crsPhilosophy);
                            crs.Philosophy = htmlConverter.Convert();
                        }
                    }
                    catch (Itenso.Rtf.RtfStructureException ex)
                    {
                        //Resume Next
                    }
                    try
                    {
                        //Convert Rationale
                        if (crs.Rationale != "" && crs.Rationale != null)
                        {
                            crsRationale = RtfInterpreterTool.BuildDoc(crs.Rationale);
                            htmlConverter = new RtfHtmlConverter(crsRationale);
                            crs.Rationale = htmlConverter.Convert();
                        }
                    }
                    catch (Itenso.Rtf.RtfStructureException ex)
                    {
                        //Resume Next
                    }
                    try
                    {
                        //Convert Description
                        if (crs.Description != "" && crs.Description != null)
                        {
                            crsDescription = RtfInterpreterTool.BuildDoc(crs.Description);
                            htmlConverter = new RtfHtmlConverter(crsDescription);
                            crs.Description = htmlConverter.Convert();
                        }
                    }
                    catch (Itenso.Rtf.RtfStructureException ex)
                    {
                        //Resume Next
                    }

                }

                SaveChanges();

                return true;
        }
        public static string ConvertRtf2Html(StreamReader rtfStream)
        {
            // image converter
            // convert all images to JPG
            RtfVisualImageAdapter imageAdapter =
               new RtfVisualImageAdapter(ImageFormat.Jpeg);
            RtfImageConvertSettings imageConvertSettings =
                           new RtfImageConvertSettings(imageAdapter);
            imageConvertSettings.ScaleImage = true; // scale images
            RtfImageConverter imageConverter =
                    new RtfImageConverter(imageConvertSettings);

            RtfParserListenerStructureBuilder structureBuilder = new RtfParserListenerStructureBuilder();
            RtfParser parser = new RtfParser(structureBuilder);
            IRtfGroup rtfStructure;
            parser.IgnoreContentAfterRootGroup = true; // support WordPad documents
            parser.Parse(new RtfSource(rtfStream));
            rtfStructure = structureBuilder.StructureRoot;
            // interpreter
            IRtfDocument rtfDocument = InterpretRtf(rtfStructure);

            // html converter
            RtfHtmlConvertSettings htmlConvertSettings =
                   new RtfHtmlConvertSettings(imageAdapter);
            htmlConvertSettings.StyleSheetLinks.Add("default.css");
            RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument,
                                                         htmlConvertSettings);
            return htmlConverter.Convert();
        }
Пример #3
0
 // ----------------------------------------------------------------------
 private void ToHtmlButtonClick( 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 );
                 RtfHtmlConverter htmlConverter = new RtfHtmlConverter( rtfDocument );
                 textBox.Text = htmlConverter.Convert();
             }
         }
     }
     catch ( Exception exception )
     {
         MessageBox.Show( this, "Error " + exception.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error );
     }
 }
Пример #4
0
 // ----------------------------------------------------------------------
 private void ToHtmlButtonClick( object sender, EventArgs e )
 {
     try
     {
         IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc( ConversionText );
         RtfHtmlConverter htmlConverter = new RtfHtmlConverter( rtfDocument );
         textBox.Text = htmlConverter.Convert();
     }
     catch ( Exception exception )
     {
         MessageBox.Show( this, "Error " + exception.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error );
     }
 }
Пример #5
0
        private static string ConvertRtfToHtml(string rtfText)
        {
            IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtfText);
            RtfHtmlConvertSettings settings = new RtfHtmlConvertSettings();
            settings.ConvertScope = RtfHtmlConvertScope.Content;

            RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument, settings);
            return htmlConverter.Convert();
        }
        public bool ConvertMyWorkspace()
        {
            IRtfDocument myDescription;
            IRtfDocument myMaterial;
            IRtfDocument myMHLE;
            IRtfDocument myModification;
            RtfHtmlConverter htmlConverter;

            //Convert MyDescription table
            foreach (MyDescription desc in _MyDescriptions)
            {
                try
                {
                    if (desc.Description != "" && desc.Description != null)
                    {
                        myDescription = RtfInterpreterTool.BuildDoc(desc.Description);
                        htmlConverter = new RtfHtmlConverter(myDescription);
                        desc.Description = htmlConverter.Convert();
                    }
                }
                catch (Itenso.Rtf.RtfStructureException ex)
                {
                    //Resume Next
                }
            }

            //Convert MyMaterial table
            foreach (MyMaterial mat in _MyMaterials)
            {
                try
                {
                    if (mat.Description != "" && mat.Description != null)
                    {
                        myDescription = RtfInterpreterTool.BuildDoc(mat.Description);
                        htmlConverter = new RtfHtmlConverter(myDescription);
                        mat.Description = htmlConverter.Convert();
                    }
                }
                catch (Itenso.Rtf.RtfStructureException ex)
                {
                    //Resume Next
                }
            }

            //Convert MyMHLE table
            foreach (MyMHLE mhle in _MyMHLEs)
            {
                try
                {
                    if (mhle.Description != "" && mhle.Description != null)
                    {
                        myDescription = RtfInterpreterTool.BuildDoc(mhle.Description);
                        htmlConverter = new RtfHtmlConverter(myDescription);
                        mhle.Description = htmlConverter.Convert();
                    }
                }
                catch (Itenso.Rtf.RtfStructureException ex)
                {
                    //Resume Next
                }
            }

            //Convert MyModification table
            foreach (MyModification mod in _MyModifications)
            {
                try
                {
                    if (mod.Description != "" && mod.Description != null)
                    {
                        myDescription = RtfInterpreterTool.BuildDoc(mod.Description);
                        htmlConverter = new RtfHtmlConverter(myDescription);
                        mod.Description = htmlConverter.Convert();
                    }
                }
                catch (Itenso.Rtf.RtfStructureException ex)
                {
                    //Resume Next
                }
            }

            SaveChanges();

            return true;
        }
        public bool ConvertLessonFields()
        {
            IRtfDocument lsnDescription;
            IRtfDocument lsnModifications;
            IRtfDocument lsnMaterials;
            IRtfDocument lsnMHLE_AS;
            IRtfDocument lsnMHLE_Purpose;
            IRtfDocument lsnMHLE_Input;
            IRtfDocument lsnMHLE_Model;
            IRtfDocument lsnMHLE_CFU;
            IRtfDocument lsnMHLE_GP;
            IRtfDocument lsnMHLE_Closure;
            IRtfDocument lsnMHLE_IP;
            RtfHtmlConverter htmlConverter;

            try
            {
                foreach (Course crs in _Courses)
                {
                    foreach (Unit unt in crs.Units)
                    {
                        foreach (Lesson lsn in unt.Lessons)
                        {
                            try
                            {
                                //Convert Description
                                if (lsn.Description != "" && lsn.Description != null)
                                {
                                    lsnDescription = RtfInterpreterTool.BuildDoc(lsn.Description);
                                    htmlConverter = new RtfHtmlConverter(lsnDescription);
                                    lsn.Description = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert Modifications
                                if (lsn.Modifications != "" && lsn.Modifications != null)
                                {
                                    lsnModifications = RtfInterpreterTool.BuildDoc(lsn.Modifications);
                                    htmlConverter = new RtfHtmlConverter(lsnModifications);
                                    lsn.Modifications = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert Materials
                                if (lsn.Materials != "" && lsn.Materials != null)
                                {
                                    lsnMaterials = RtfInterpreterTool.BuildDoc(lsn.Materials);
                                    htmlConverter = new RtfHtmlConverter(lsnMaterials);
                                    lsn.Materials = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_AS
                                if (lsn.MHLEAS != "" && lsn.MHLEAS != null)
                                {
                                    lsnMHLE_AS = RtfInterpreterTool.BuildDoc(lsn.MHLEAS);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_AS);
                                    lsn.MHLEAS = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_Purpose
                                if (lsn.MHLEPurpose != "" && lsn.MHLEPurpose != null)
                                {
                                    lsnMHLE_Purpose = RtfInterpreterTool.BuildDoc(lsn.MHLEPurpose);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_Purpose);
                                    lsn.MHLEPurpose = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_Input
                                if (lsn.MHLEInput != "" && lsn.MHLEInput != null)
                                {
                                    lsnMHLE_Input = RtfInterpreterTool.BuildDoc(lsn.MHLEInput);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_Input);
                                    lsn.MHLEInput = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_Model
                                if (lsn.MHLEModel != "" && lsn.MHLEModel != null)
                                {
                                    lsnMHLE_Model = RtfInterpreterTool.BuildDoc(lsn.MHLEModel);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_Model);
                                    lsn.MHLEModel = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_CFU
                                if (lsn.MHLECFU != "" && lsn.MHLECFU != null)
                                {
                                    lsnMHLE_CFU = RtfInterpreterTool.BuildDoc(lsn.MHLECFU);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_CFU);
                                    lsn.MHLECFU = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_GP
                                if (lsn.MHLEGP != "" && lsn.MHLEGP != null)
                                {
                                    lsnMHLE_GP = RtfInterpreterTool.BuildDoc(lsn.MHLEGP);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_GP);
                                    lsn.MHLEGP = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_Closure
                                if (lsn.MHLEClosure != "" && lsn.MHLEClosure != null)
                                {
                                    lsnMHLE_Closure = RtfInterpreterTool.BuildDoc(lsn.MHLEClosure);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_Closure);
                                    lsn.MHLEClosure = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }
                            try
                            {
                                //Convert MHLE_IP
                                if (lsn.MHLEIP != "" && lsn.MHLEIP != null)
                                {
                                    lsnMHLE_IP = RtfInterpreterTool.BuildDoc(lsn.MHLEIP);
                                    htmlConverter = new RtfHtmlConverter(lsnMHLE_IP);
                                    lsn.MHLEIP = htmlConverter.Convert();
                                }
                            }
                            catch (Itenso.Rtf.RtfStructureException ex)
                            {
                                //Resume Next
                            }

                            //Convert Lesson Objectives
                            foreach (LessonObjective obj in lsn.LessonObjectives)
                            {
                                lsn.DailyObjectives += obj.Number + ". " + obj.Description + "     ";
                            }
                        }
                    }
                }

                SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }
        // ----------------------------------------------------------------------
        private string ConvertHmtl( IRtfDocument rtfDocument, IRtfVisualImageAdapter imageAdapter )
        {
            string html;

            try
            {
                RtfHtmlConvertSettings htmlConvertSettings = new RtfHtmlConvertSettings( imageAdapter );
                if ( settings.CharacterSet != null )
                {
                    htmlConvertSettings.CharacterSet = settings.CharacterSet;
                }
                htmlConvertSettings.Title = settings.SourceFileNameWithoutExtension;
                htmlConvertSettings.ImagesPath = settings.ImagesPath;
                htmlConvertSettings.IsShowHiddenText = settings.ShowHiddenText;
                htmlConvertSettings.UseNonBreakingSpaces = settings.UseNonBreakingSpaces;
                if ( settings.ConvertScope != RtfHtmlConvertScope.None )
                {
                    htmlConvertSettings.ConvertScope = settings.ConvertScope;
                }
                if ( !string.IsNullOrEmpty( settings.StyleSheets ) )
                {
                    string[] styleSheets = settings.StyleSheets.Split( ',' );
                    htmlConvertSettings.StyleSheetLinks.AddRange( styleSheets );
                }
                htmlConvertSettings.ConvertVisualHyperlinks = settings.ConvertVisualHyperlinks;
                if ( !string.IsNullOrEmpty( settings.VisualHyperlinkPattern ) )
                {
                    htmlConvertSettings.VisualHyperlinkPattern = settings.VisualHyperlinkPattern;
                }
                htmlConvertSettings.SpecialCharsRepresentation = settings.SpecialCharsRepresentation;

                RtfHtmlConverter htmlConverter = new RtfHtmlConverter( rtfDocument, htmlConvertSettings );
                html = htmlConverter.Convert();
            }
            catch ( Exception e )
            {
                Console.WriteLine( "error while converting to html: " + e.Message );
                ExitCode = ProgramExitCode.ConvertHtml;
                return null;
            }

            return html;
        }