Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Work (RTF to XML) ?? #2

Open
pc8181 opened this issue Feb 24, 2018 · 4 comments
Open

How to Work (RTF to XML) ?? #2

pc8181 opened this issue Feb 24, 2018 · 4 comments

Comments

@pc8181
Copy link

pc8181 commented Feb 24, 2018

how to work with this library for RTF to XML ?

my rtbx has different style font with content i want to extract the text with it's font, is't possible ?

Thanks

@Shereef
Copy link
Owner

Shereef commented Feb 26, 2018 via email

@pc8181
Copy link
Author

pc8181 commented Feb 26, 2018

Thanks for your reply sir ...

RTBX = Rich Text Box
I am using Rich Text Box for different type of font styles

Thanks

@Shereef
Copy link
Owner

Shereef commented Feb 27, 2018

Sorry for the late reply, if you find this file after cloning and then navigate in the solution to this file i think you'll get the gist of it

@pc8181
Copy link
Author

pc8181 commented Feb 27, 2018

i need XML .... k sir thnks for your reply i managed it ....

my stackoverflow is about RTF to XML
https://stackoverflow.com/questions/49005971/vb-net-rtf-to-required-xml-format

i tried like this


        _lamParseRTF = Function()
                               Dim rtfStructure As IRtfGroup
                               Dim parserLogger As RtfParserListenerFileLogger = Nothing
                               Try
                                   Using stream As FileStream = File.Open(_tmpRTFFile$, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
                                       ' parse the rtf structure
                                       Dim structureBuilder As New RtfParserListenerStructureBuilder()
                                       Dim parser As New RtfParser(structureBuilder)
                                       parser.IgnoreContentAfterRootGroup = True ' support WordPad documents
                                       If parserLogger IsNot Nothing Then
                                           parser.AddParserListener(parserLogger)
                                       End If
                                       parser.Parse(New RtfSource(stream))
                                       rtfStructure = structureBuilder.StructureRoot
                                   End Using
                               Catch ef As Exception
                                   If parserLogger IsNot Nothing Then
                                       parserLogger.Dispose()
                                   End If
                                   Trace.WriteLine("error while parsing rtf: " & ef.Message)
                                   Return Nothing
                               End Try
                               Return rtfStructure
                           End Function
                _lamInterPreterRTF = Function(rtfStructure As IRtfGroup) As IRtfDocument
                                     Dim rtfDocument As IRtfDocument
                                     Dim interpreterLogger As RtfInterpreterListenerFileLogger = Nothing
                                     Try
                                      Dim interpreterSettings As New Itenso.Rtf.Interpreter.RtfInterpreterSettings()
                                         interpreterSettings.IgnoreDuplicatedFonts = False
                                         interpreterSettings.IgnoreUnknownFonts = False

                                      
                                         rtfDocument = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterLogger)
                                     Catch edf As Exception
                                         If interpreterLogger IsNot Nothing Then
                                             interpreterLogger.Dispose()
                                         End If

                                         Trace.WriteLine("error while interpreting rtf: " & edf.Message)
                                         Return Nothing
                                     End Try
                                     Return rtfDocument
                                 End Function ' InterpretRtf
            _lamConvertXML = Function(rtfDocumentHere As IRtfDocument)
                                 Try
                                     Dim xmlWriterSettings As New XmlWriterSettings()
                                     xmlWriterSettings.Indent = True
                                     xmlWriterSettings.IndentChars = ("  ")
                                     xmlWriterSettings.Encoding = Encoding.Unicode

                                     Using writer As XmlWriter = XmlWriter.Create(_tmpXMLFile$, xmlWriterSettings)
                                         Dim xmlConvertSettings As New RtfXmlConvertSettings()
                                         '  xmlConvertSettings.Prefix = ""
                                         '  xmlConvertSettings.Ns = ""
                                         '   xmlConvertSettings.IsShowHiddenText = False
                                         Dim xmlConverter As New RtfXmlConverter(rtfDocumentHere, writer, xmlConvertSettings)
                                         xmlConverter.Convert()
                                         writer.Flush()
                                     End Using
                                 Catch eff As Exception
                                     Trace.WriteLine("error while converting to xml: " & eff.Message)
                                 End Try
                                 Return True
                             End Function ' ConvertXml


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants