using System; using System.IO; using System.Text; using Microsoft.Dynamics.Framework.UI.Extensibility; using Itenso.Rtf; using Itenso.Rtf.Parser; using Itenso.Rtf.Support; using Itenso.Rtf.Converter.Image; using Itenso.Rtf.Converter.Html; using Itenso.Rtf.Interpreter; using System.Drawing.Imaging; namespace RTF2HTMLConverter { [ControlAddInExport("RTF2HTMLConverter")] //5a33fb4258a0a66c public class Converter { string HTML; public string RTF { get { return HTML; } set { MemoryStream RTFStream = new MemoryStream(Encoding.UTF8.GetBytes(RTF)); // Parse RTF IRtfGroup RTFStructure; RtfParserListenerStructureBuilder StructureBuilder = new RtfParserListenerStructureBuilder(); RtfParser Parser = new RtfParser(StructureBuilder); Parser.IgnoreContentAfterRootGroup = true; Parser.Parse(new RtfSource(RTFStream)); RTFStructure = StructureBuilder.StructureRoot; RtfVisualImageAdapter imageAdapter = new RtfVisualImageAdapter("C:\\TEMP\\",ImageFormat.Jpeg); // Interpret RTF IRtfDocument RTFDocument; RtfInterpreterSettings InterpreterSettings = new RtfInterpreterSettings(); InterpreterSettings.IgnoreDuplicatedFonts = true; InterpreterSettings.IgnoreUnknownFonts = true; RTFDocument = RtfInterpreterTool.BuildDoc(RTFStructure, InterpreterSettings); // Convert RTF to HTML RtfHtmlConvertSettings HTMLConvertSettings = new RtfHtmlConvertSettings(); HTMLConvertSettings.Title = "Converted from RTF"; HTMLConvertSettings.IsShowHiddenText = true; HTMLConvertSettings.UseNonBreakingSpaces = true; RtfHtmlConverter HTMLConverter = new RtfHtmlConverter(RTFDocument, HTMLConvertSettings); HTML = HTMLConverter.Convert(); } } } }
RTFDocument = RtfInterpreterTool.BuildDoc(RTFStructure, InterpreterSettings);
public static IRtfDocument BuildDoc(IRtfGroup rtfDocument, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(IRtfSource rtfTextSource, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(Stream rtfTextSource, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(string rtfText, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(TextReader rtfTextSource, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(IRtfGroup rtfDocument, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(IRtfSource rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(Stream rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(string rtfText, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(TextReader rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);
Name DataType Subtype Length RtfSource Text MemoryStream DotNet System.IO.MemoryStream.'mscorlib' Encoding DotNet System.Text.Encoding.'mscorlib' Convert DotNet System.Convert.'mscorlib' --PARSE Boolean IRtfGroup DotNet Itenso.Rtf.IRtfGroup.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfGroup DotNet Itenso.Rtf.Model.RtfGroup.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfParserListenerStructureBuilder DotNet Itenso.Rtf.Parser.RtfParserListenerStructureBuilder.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfParser DotNet Itenso.Rtf.Parser.RtfParser.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfStructureBuilder DotNet Itenso.Rtf.Parser.RtfParserListenerStructureBuilder.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfVisualImageAdapter DotNet Itenso.Rtf.Converter.Image.RtfVisualImageAdapter.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' ImageFormat DotNet System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' --INTERPRET Boolean IRtfDocument DotNet Itenso.Rtf.IRtfDocument.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfDocument DotNet Itenso.Rtf.Model.RtfDocument.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfInterpreterSettings DotNet Itenso.Rtf.Interpreter.RtfInterpreterSettings.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' IRtfInterpreterSettings DotNet Itenso.Rtf.IRtfInterpreterSettings.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' RtfInterpreterTool DotNet Itenso.Rtf.Support.RtfInterpreterTool.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' Documentation() OnRun() RtfSource := '{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\*\generator Riched20 10.0.14393}\viewkind4\uc1\pard\sa200\sl276\slmult1\b\f0\fs22\lang9 TEST\b0\par}'; MemoryStream := MemoryStream.MemoryStream(Convert.ToByte(Encoding.GetEncoding('UTF8').GetBytes(RtfSource))); // Parse RTF IRtfGroup := RtfGroup; RtfParserListenerStructureBuilder := RtfParserListenerStructureBuilder.RtfParserListenerStructureBuilder; RtfParser := RtfParser.RtfParser; RtfParser.AddParserListener(RtfParserListenerStructureBuilder); RtfParser.IgnoreContentAfterRootGroup := TRUE; RtfParser.Parse(MemoryStream); RtfStructureBuilder := RtfParserListenerStructureBuilder.StructureRoot; RtfVisualImageAdapter := RtfVisualImageAdapter.RtfVisualImageAdapter('C:\TEMP\',ImageFormat.Jpeg); //Interpret RTF IRtfDocument := RtfDocument; IRtfInterpreterSettings := RtfInterpreterSettings; RtfInterpreterSettings := RtfInterpreterSettings.RtfInterpreterSettings; RtfInterpreterSettings.IgnoreDuplicatedFonts := TRUE; RtfInterpreterSettings.IgnoreUnknownFonts := TRUE; RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings);
DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
Answers
Just a shot in the blue, but maybe it helps.
Good shout! I'll check ot out! Thanks
Only solution I have found is to break it down and call the various bits individually.
You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:
Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.
Then you call BuildDoc like with the array as the last parameter:
Thank you very much! It worked!