├── ThirdLib ├── SLF.dll ├── cli_ure.dll ├── cli_basetypes.dll ├── cli_oootypes.dll ├── cli_uretypes.dll ├── cli_cppuhelper.dll ├── net.sf.dotnetcli.dll └── Dotnet.Commons.IO.dll ├── NODConverter.Cli ├── app.config ├── Properties │ └── AssemblyInfo.cs ├── NODConverter.Cli.csproj └── Program.cs ├── NODConverter ├── XmlDocumentFormatRegistry.cs ├── IDocumentFormatRegistry.cs ├── LoggerFactory.cs ├── OpenOffice │ ├── Connection │ │ ├── OpenOfficeException.cs │ │ ├── IOpenOfficeConnection.cs │ │ ├── PipeOpenOfficeConnection.cs │ │ ├── SocketOpenOfficeConnection.cs │ │ ├── OpenOfficeConfiguration.cs │ │ └── AbstractOpenOfficeConnection.cs │ └── Converter │ │ ├── OOStreamHelper.cs │ │ ├── StreamOpenOfficeDocumentConverter.cs │ │ ├── AbstractOpenOfficeDocumentConverter.cs │ │ └── OpenOfficeDocumentConverter.cs ├── Properties │ └── AssemblyInfo.cs ├── DocumentFamily.cs ├── SocketUtils.cs ├── BasicDocumentFormatRegistry.cs ├── IDocumentConverter.cs ├── NODConverter.csproj ├── DocumentFormat.cs ├── EnvUtils.cs ├── DefaultDocumentFormatRegistry.cs └── SupportClass.cs ├── README.md ├── NODConverter.sln └── .gitignore /ThirdLib/SLF.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/SLF.dll -------------------------------------------------------------------------------- /ThirdLib/cli_ure.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/cli_ure.dll -------------------------------------------------------------------------------- /ThirdLib/cli_basetypes.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/cli_basetypes.dll -------------------------------------------------------------------------------- /ThirdLib/cli_oootypes.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/cli_oootypes.dll -------------------------------------------------------------------------------- /ThirdLib/cli_uretypes.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/cli_uretypes.dll -------------------------------------------------------------------------------- /ThirdLib/cli_cppuhelper.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/cli_cppuhelper.dll -------------------------------------------------------------------------------- /ThirdLib/net.sf.dotnetcli.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/net.sf.dotnetcli.dll -------------------------------------------------------------------------------- /ThirdLib/Dotnet.Commons.IO.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeyu/NODConverter/HEAD/ThirdLib/Dotnet.Commons.IO.dll -------------------------------------------------------------------------------- /NODConverter.Cli/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /NODConverter/XmlDocumentFormatRegistry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NODConverter 6 | { 7 | public class XmlDocumentFormatRegistry 8 | { 9 | //to do 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## NODConverter 2 | 3 | NODConverter is a pure .NET library written in C# and is a port of open source Java Convert framework, JODConverter. 4 | 5 | NODConverter automates conversions between office document formats using OpenOffice.org or LibreOffice. 6 | -------------------------------------------------------------------------------- /NODConverter/IDocumentFormatRegistry.cs: -------------------------------------------------------------------------------- 1 | namespace NODConverter 2 | { 3 | public interface IDocumentFormatRegistry 4 | { 5 | 6 | DocumentFormat GetFormatByFileExtension(string extension); 7 | 8 | DocumentFormat GetFormatByMimeType(string extension); 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NODConverter/LoggerFactory.cs: -------------------------------------------------------------------------------- 1 | using Slf; 2 | 3 | namespace NODConverter 4 | { 5 | public class LoggerFactory 6 | { 7 | public static ILogger GetLogger() 8 | { 9 | ILogger logger = new ConsoleLogger(); 10 | LoggerService.SetLogger(logger); 11 | return LoggerService.GetLogger(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Connection/OpenOfficeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NODConverter.OpenOffice.Connection 4 | { 5 | public class OpenOfficeException : Exception 6 | { 7 | 8 | //private const long SerialVersionUid = 1L; 9 | 10 | public OpenOfficeException(string message) 11 | : base(message) 12 | { 13 | } 14 | 15 | public OpenOfficeException(string message, Exception cause) 16 | : base(message, cause) 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Connection/IOpenOfficeConnection.cs: -------------------------------------------------------------------------------- 1 | using unoidl.com.sun.star.bridge; 2 | using unoidl.com.sun.star.frame; 3 | using unoidl.com.sun.star.lang; 4 | using unoidl.com.sun.star.ucb; 5 | using unoidl.com.sun.star.uno; 6 | namespace NODConverter.OpenOffice.Connection 7 | { 8 | public interface IOpenOfficeConnection 9 | { 10 | void Connect(); 11 | 12 | void Disconnect(); 13 | 14 | bool Connected { get; } 15 | 16 | /// the com.sun.star.frame.Desktop service 17 | XComponentLoader Desktop { get; } 18 | 19 | /// the com.sun.star.ucb.FileContentProvider service 20 | XFileIdentifierConverter FileContentProvider { get; } 21 | 22 | XBridge Bridge { get; } 23 | 24 | XMultiComponentFactory RemoteServiceManager { get; } 25 | 26 | XComponentContext ComponentContext { get; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Connection/PipeOpenOfficeConnection.cs: -------------------------------------------------------------------------------- 1 | namespace NODConverter.OpenOffice.Connection 2 | { 3 | /// 4 | /// OpenOffice connection using a named pipe 5 | ///

6 | /// Warning! This requires the sal3 native library shipped with OpenOffice.org; 7 | /// it must be made available via the java.library.path parameter, e.g. 8 | ///

 9 |     ///   java -Djava.library.path=/opt/openoffice.org/program my.App
10 |     /// 
11 | ///
12 | public class PipeOpenOfficeConnection : AbstractOpenOfficeConnection 13 | { 14 | 15 | public const string DefaultPipeName = "nodconverter"; 16 | 17 | public PipeOpenOfficeConnection() 18 | : this(DefaultPipeName) 19 | { 20 | } 21 | 22 | public PipeOpenOfficeConnection(string pipeName) 23 | : base("pipe,name=" + pipeName) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /NODConverter.Cli/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Nod")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Nod")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("c1ad74d2-983a-4bdd-b7b5-af96cf2f59d0")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Connection/SocketOpenOfficeConnection.cs: -------------------------------------------------------------------------------- 1 | namespace NODConverter.OpenOffice.Connection 2 | { 3 | public class SocketOpenOfficeConnection : AbstractOpenOfficeConnection 4 | { 5 | 6 | public const string DefaultHost = "127.0.0.1"; 7 | public const int DefaultPort = 8100; 8 | public readonly string CmdName = "soffice"; 9 | public readonly string CmdArguments = string.Format("-headless -accept=\"socket,host={0},port={1};urp;\" -nofirststartwizard", DefaultHost, DefaultPort); 10 | public SocketOpenOfficeConnection() 11 | : this(DefaultHost, DefaultPort) 12 | { 13 | } 14 | 15 | public SocketOpenOfficeConnection(int port) 16 | : this(DefaultHost, port) 17 | { 18 | } 19 | 20 | public SocketOpenOfficeConnection(string host, int port) 21 | : base("socket,host=" + host + ",port=" + port + ",tcpNoDelay=1") 22 | { 23 | CmdArguments = string.Format("-headless -accept=\"socket,host={0},port={1};urp;\" -nofirststartwizard", host, port); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NODConverter/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("NODConverter")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NODConverter")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("6a77df25-a3c4-4daf-8c5c-b45be3f717e8")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NODConverter/DocumentFamily.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace NODConverter 5 | { 6 | /// 7 | /// Enum-style class declaring the available document families (Text, Spreadsheet, Presentation). 8 | /// 9 | public class DocumentFamily 10 | { 11 | 12 | public static readonly DocumentFamily Text = new DocumentFamily("Text"); 13 | public static readonly DocumentFamily Spreadsheet = new DocumentFamily("Spreadsheet"); 14 | public static readonly DocumentFamily Presentation = new DocumentFamily("Presentation"); 15 | public static readonly DocumentFamily Drawing = new DocumentFamily("Drawing"); 16 | 17 | private static readonly IDictionary Families = new Hashtable(); 18 | static DocumentFamily() 19 | { 20 | Families[Text._name] = Text; 21 | Families[Spreadsheet._name] = Spreadsheet; 22 | Families[Presentation._name] = Presentation; 23 | Families[Drawing._name] = Drawing; 24 | } 25 | 26 | private readonly string _name; 27 | 28 | private DocumentFamily(string name) 29 | { 30 | _name = name; 31 | } 32 | 33 | public virtual string Name 34 | { 35 | get 36 | { 37 | return _name; 38 | } 39 | } 40 | 41 | public static DocumentFamily GetFamily(string name) 42 | { 43 | DocumentFamily family = (DocumentFamily)Families[name]; 44 | if (family == null) 45 | { 46 | throw new ArgumentException("invalid DocumentFamily: " + name); 47 | } 48 | return family; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /NODConverter/SocketUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using unoidl.com.sun.star.ucb; 9 | 10 | namespace NODConverter 11 | { 12 | public class SocketUtils 13 | { 14 | [StructLayout(LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Ansi)] 15 | public struct WSAData 16 | { 17 | public short wVersion; 18 | public short wHighVersion; 19 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 257)] 20 | public string szDescription; 21 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 129)] 22 | public string szSystemStatus; 23 | public short iMaxSockets; 24 | public short iMaxUdpDg; 25 | public IntPtr lpVendorInfo; 26 | } 27 | 28 | [DllImport("ws2_32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)] 29 | static extern Int32 WSAStartup(Int16 wVersionRequested, ref WSAData wsaData); 30 | 31 | [DllImport("ws2_32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)] 32 | static extern Int32 WSACleanup(); 33 | 34 | 35 | public static void Connect() 36 | { 37 | WSAData data = new WSAData(); 38 | int result = 0; 39 | 40 | data.wHighVersion = 2; 41 | data.wVersion = 2; 42 | 43 | result = WSAStartup(36, ref data); 44 | if (result != 0) 45 | { 46 | throw new Exception("socket connect failure!"); 47 | } 48 | } 49 | public static void Disconnect() 50 | { 51 | WSACleanup(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /NODConverter/BasicDocumentFormatRegistry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace NODConverter 4 | { 5 | public class BasicDocumentFormatRegistry : IDocumentFormatRegistry 6 | { 7 | 8 | private readonly IList _documentFormats = new ArrayList(); // 9 | 10 | public virtual void AddDocumentFormat(DocumentFormat documentFormat) 11 | { 12 | _documentFormats.Add(documentFormat); 13 | } 14 | 15 | protected internal virtual IList DocumentFormats 16 | { 17 | get 18 | { 19 | return _documentFormats; 20 | } 21 | } 22 | 23 | /// the file extension 24 | /// the DocumentFormat for this extension, or null if the extension is not mapped 25 | public virtual DocumentFormat GetFormatByFileExtension(string extension) 26 | { 27 | if (extension == null) 28 | { 29 | return null; 30 | } 31 | string lowerExtension = extension.ToLower(); 32 | for (IEnumerator it = _documentFormats.GetEnumerator(); it.MoveNext(); ) 33 | { 34 | DocumentFormat format = (DocumentFormat)it.Current; 35 | if (format != null && format.FileExtension.Equals(lowerExtension)) 36 | { 37 | return format; 38 | } 39 | } 40 | return null; 41 | } 42 | 43 | public virtual DocumentFormat GetFormatByMimeType(string mimeType) 44 | { 45 | for (IEnumerator it = _documentFormats.GetEnumerator(); it.MoveNext(); ) 46 | { 47 | DocumentFormat format = (DocumentFormat)it.Current; 48 | if (format != null && format.MimeType.Equals(mimeType)) 49 | { 50 | return format; 51 | } 52 | } 53 | return null; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /NODConverter/IDocumentConverter.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace NODConverter 4 | { 5 | public interface IDocumentConverter 6 | { 7 | 8 | /// Convert a document. 9 | ///

10 | /// Note that this method does not close inputStream and outputStream. 11 | /// 12 | ///

13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | void Convert(Stream inputStream, DocumentFormat inputFormat, Stream outputStream, DocumentFormat outputFormat); 22 | 23 | /// Convert a document. 24 | /// 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | void Convert(FileInfo inputFile, DocumentFormat inputFormat, FileInfo outputFile, DocumentFormat outputFormat); 35 | 36 | 37 | /// Convert a document. The input format is guessed from the file extension. 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | /// 44 | /// 45 | /// 46 | void Convert(FileInfo inputDocument, FileInfo outputDocument, DocumentFormat outputFormat); 47 | 48 | /// Convert a document. Both input and output formats are guessed from the file extension. 49 | /// 50 | /// 51 | /// 52 | /// 53 | /// 54 | /// 55 | void Convert(FileInfo inputDocument, FileInfo outputDocument); 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Converter/OOStreamHelper.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using unoidl.com.sun.star.io; 3 | 4 | namespace NODConverter.OpenOffice.Converter 5 | { 6 | public class XOutputStreamWrapper : XOutputStream 7 | { 8 | private readonly Stream _ostream; 9 | 10 | public XOutputStreamWrapper(Stream ostream) 11 | { 12 | _ostream = ostream; 13 | } 14 | 15 | public void closeOutput() 16 | { 17 | _ostream.Close(); 18 | } 19 | 20 | public void flush() 21 | { 22 | _ostream.Flush(); 23 | } 24 | 25 | public void writeBytes(byte[] b) 26 | { 27 | _ostream.Write(b, 0, b.Length); 28 | } 29 | } 30 | 31 | public class XInputStreamWrapper : XInputStream, XSeekable 32 | { 33 | private readonly Stream _instream; 34 | 35 | public XInputStreamWrapper(Stream instream) 36 | { 37 | _instream = instream; 38 | } 39 | 40 | // XInputStream interface 41 | public int readBytes(out byte[] data, int length) 42 | { 43 | int remaining = (int)(_instream.Length - _instream.Position); 44 | int l = length > remaining ? remaining : length; 45 | data = new byte[length]; 46 | return _instream.Read(data, 0, l); 47 | } 48 | 49 | public int readSomeBytes(out byte[] data, int length) 50 | { 51 | int remaining = (int)(_instream.Length - _instream.Position); 52 | int l = length > remaining ? remaining : length; 53 | data = new byte[length]; 54 | return _instream.Read(data, 0, l); 55 | } 56 | 57 | public void skipBytes(int nToSkip) 58 | { 59 | _instream.Seek(nToSkip, SeekOrigin.Current); 60 | } 61 | 62 | public int available() 63 | { 64 | return (int)(_instream.Length - _instream.Position); 65 | } 66 | 67 | public void closeInput() 68 | { 69 | _instream.Close(); 70 | } 71 | 72 | // XSeekable interface 73 | public long getPosition() 74 | { 75 | return _instream.Position; 76 | } 77 | 78 | public long getLength() 79 | { 80 | return _instream.Length; 81 | } 82 | 83 | public void seek(long pos) 84 | { 85 | _instream.Seek(pos, SeekOrigin.Begin); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /NODConverter.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NODConverter", "NODConverter\NODConverter.csproj", "{7C1FD497-39E3-42F0-8E91-46582C2C5CEA}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NODConverter.Cli", "NODConverter.Cli\NODConverter.Cli.csproj", "{CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|Mixed Platforms = Debug|Mixed Platforms 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|Mixed Platforms = Release|Mixed Platforms 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 21 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 22 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Debug|x86.ActiveCfg = Debug|Any CPU 23 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 26 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Release|Mixed Platforms.Build.0 = Release|Any CPU 27 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA}.Release|x86.ActiveCfg = Release|Any CPU 28 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Debug|Any CPU.ActiveCfg = Debug|x86 29 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 30 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Debug|Mixed Platforms.Build.0 = Debug|x86 31 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Debug|x86.ActiveCfg = Debug|x86 32 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Debug|x86.Build.0 = Debug|x86 33 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Release|Any CPU.ActiveCfg = Release|x86 34 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Release|Mixed Platforms.ActiveCfg = Release|x86 35 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Release|Mixed Platforms.Build.0 = Release|x86 36 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Release|x86.ActiveCfg = Release|x86 37 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F}.Release|x86.Build.0 = Release|x86 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /NODConverter.Cli/NODConverter.Cli.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {CB21935B-0A5F-44F8-82D5-2F7CF6BEC01F} 9 | Exe 10 | Properties 11 | NODConverter.Cli 12 | Nod 13 | v4.0 14 | 512 15 | 16 | 17 | 18 | x86 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x86 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | False 39 | ..\ThirdLib\cli_uretypes.dll 40 | 41 | 42 | ..\ThirdLib\net.sf.dotnetcli.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA} 55 | NODConverter 56 | 57 | 58 | 59 | 60 | 61 | 62 | 69 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Connection/OpenOfficeConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using uno; 3 | using unoidl.com.sun.star.beans; 4 | using unoidl.com.sun.star.container; 5 | using unoidl.com.sun.star.lang; 6 | 7 | namespace NODConverter.OpenOffice.Connection 8 | { 9 | /// 10 | /// Utility class to access OpenOffice.org configuration properties at runtime 11 | /// 12 | public class OpenOfficeConfiguration 13 | { 14 | 15 | public const string NodeL10N = "org.openoffice.Setup/L10N"; 16 | public const string NodeProduct = "org.openoffice.Setup/Product"; 17 | 18 | private readonly IOpenOfficeConnection _connection; 19 | 20 | public OpenOfficeConfiguration(IOpenOfficeConnection connection) 21 | { 22 | _connection = connection; 23 | } 24 | 25 | public virtual string GetOpenOfficeProperty(string nodePath, string node) 26 | { 27 | if (!nodePath.StartsWith("/")) 28 | { 29 | nodePath = "/" + nodePath; 30 | } 31 | Any property; 32 | // create the provider and remember it as a XMultiServiceFactory 33 | try 34 | { 35 | const string sProviderService = "com.sun.star.configuration.ConfigurationProvider"; 36 | object configProvider = _connection.RemoteServiceManager.createInstanceWithContext(sProviderService, _connection.ComponentContext); 37 | XMultiServiceFactory xConfigProvider = (XMultiServiceFactory)configProvider; 38 | 39 | // The service name: Need only read access: 40 | const string sReadOnlyView = "com.sun.star.configuration.ConfigurationAccess"; 41 | // creation arguments: nodepath 42 | PropertyValue aPathArgument = new PropertyValue 43 | { 44 | Name = "nodepath", 45 | Value = new Any(nodePath) 46 | }; 47 | Any[] aArguments = new Any[1]; 48 | aArguments[0] = aPathArgument.Value; 49 | 50 | // create the view 51 | //XInterface xElement = (XInterface) xConfigProvider.createInstanceWithArguments(sReadOnlyView, aArguments); 52 | XNameAccess xChildAccess = (XNameAccess)xConfigProvider.createInstanceWithArguments(sReadOnlyView, aArguments); 53 | 54 | // get the value 55 | property = xChildAccess.getByName(node); 56 | } 57 | catch (Exception exception) 58 | { 59 | throw new OpenOfficeException("Could not retrieve property", exception); 60 | } 61 | return property.ToString(); 62 | } 63 | 64 | public virtual string OpenOfficeVersion 65 | { 66 | get 67 | { 68 | try 69 | { 70 | // OOo >= 2.2 returns major.minor.micro 71 | return GetOpenOfficeProperty(NodeProduct, "ooSetupVersionAboutBox"); 72 | } 73 | catch (OpenOfficeException) 74 | { 75 | // OOo < 2.2 only returns major.minor 76 | return GetOpenOfficeProperty(NodeProduct, "ooSetupVersion"); 77 | } 78 | } 79 | } 80 | 81 | public virtual string OpenOfficeLocale 82 | { 83 | get 84 | { 85 | return GetOpenOfficeProperty(NodeL10N, "ooLocale"); 86 | } 87 | } 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /NODConverter/NODConverter.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {7C1FD497-39E3-42F0-8E91-46582C2C5CEA} 9 | Library 10 | Properties 11 | NODConverter 12 | NODConverter 13 | v4.0 14 | 512 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | x86 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\ThirdLib\cli_basetypes.dll 38 | 39 | 40 | ..\ThirdLib\cli_cppuhelper.dll 41 | 42 | 43 | ..\ThirdLib\cli_oootypes.dll 44 | 45 | 46 | ..\ThirdLib\cli_ure.dll 47 | 48 | 49 | ..\ThirdLib\cli_uretypes.dll 50 | 51 | 52 | ..\ThirdLib\Dotnet.Commons.IO.dll 53 | 54 | 55 | 56 | ..\ThirdLib\net.sf.dotnetcli.dll 57 | 58 | 59 | ..\ThirdLib\SLF.dll 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 98 | -------------------------------------------------------------------------------- /NODConverter/DocumentFormat.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace NODConverter 4 | { 5 | /// 6 | /// Represents a document format ("OpenDocument Text" or "PDF"). 7 | /// Also contains its available export filters. 8 | /// 9 | public class DocumentFormat 10 | { 11 | 12 | private const string FilterName = "FilterName"; 13 | 14 | private readonly string _name; 15 | private readonly DocumentFamily _family; 16 | private readonly string _mimeType; 17 | private readonly string _fileExtension; 18 | private readonly IDictionary _exportOptions = new Hashtable(); //> 19 | private readonly IDictionary _importOptions = new Hashtable(); // 20 | 21 | public DocumentFormat() 22 | { 23 | // empty constructor needed for XStream deserialization 24 | } 25 | 26 | public DocumentFormat(string name, string mimeType, string extension) 27 | { 28 | _name = name; 29 | _mimeType = mimeType; 30 | _fileExtension = extension; 31 | } 32 | 33 | public DocumentFormat(string name, DocumentFamily family, string mimeType, string extension) 34 | { 35 | _name = name; 36 | _family = family; 37 | _mimeType = mimeType; 38 | _fileExtension = extension; 39 | } 40 | 41 | public virtual string Name 42 | { 43 | get 44 | { 45 | return _name; 46 | } 47 | } 48 | 49 | public virtual DocumentFamily Family 50 | { 51 | get 52 | { 53 | return _family; 54 | } 55 | } 56 | 57 | public virtual string MimeType 58 | { 59 | get 60 | { 61 | return _mimeType; 62 | } 63 | } 64 | 65 | public virtual string FileExtension 66 | { 67 | get 68 | { 69 | return _fileExtension; 70 | } 71 | } 72 | 73 | private string GetExportFilter(DocumentFamily family) 74 | { 75 | return (string)GetExportOptions(family)[FilterName]; 76 | } 77 | 78 | public virtual bool Importable 79 | { 80 | get 81 | { 82 | return _family != null; 83 | } 84 | } 85 | 86 | public virtual bool ExportOnly 87 | { 88 | get 89 | { 90 | return !Importable; 91 | } 92 | } 93 | 94 | public virtual bool IsExportableTo(DocumentFormat otherFormat) 95 | { 96 | return otherFormat.IsExportableFrom(_family); 97 | } 98 | 99 | public virtual bool IsExportableFrom(DocumentFamily family) 100 | { 101 | return GetExportFilter(family) != null; 102 | } 103 | 104 | public virtual void SetExportFilter(DocumentFamily family, string filter) 105 | { 106 | GetExportOptions(family)[FilterName] = filter; 107 | } 108 | 109 | public virtual void SetExportOption(DocumentFamily family, string name, object value) 110 | { 111 | IDictionary options = (IDictionary)_exportOptions[family]; // 112 | if (options == null) 113 | { 114 | options = new Hashtable(); 115 | _exportOptions[family] = options; 116 | } 117 | options[name] = value; 118 | } 119 | 120 | public virtual IDictionary GetExportOptions(DocumentFamily family) // 121 | { 122 | IDictionary options = (IDictionary)_exportOptions[family]; // 123 | if (options == null) 124 | { 125 | options = new Hashtable(); 126 | _exportOptions[family] = options; 127 | } 128 | return options; 129 | } 130 | 131 | public virtual void SetImportOption(string name, object value) 132 | { 133 | _importOptions[name] = value; 134 | } 135 | 136 | public virtual IDictionary ImportOptions 137 | { 138 | get 139 | { 140 | if (_importOptions != null) 141 | { 142 | return _importOptions; 143 | } 144 | else 145 | { 146 | return new Hashtable(); 147 | } 148 | } 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /NODConverter/EnvUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics; 6 | using System.IO; 7 | namespace NODConverter 8 | { 9 | public static class EnvUtils 10 | { 11 | public static void InitUno() 12 | { 13 | var info = Get(); 14 | if(info.Kind == OfficeKind.LibreOffice) 15 | { 16 | Environment.SetEnvironmentVariable("UNO_PATH", info.OfficeUnoPath, EnvironmentVariableTarget.Process); 17 | Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";" + info.OfficeUnoPath, EnvironmentVariableTarget.Process); 18 | } 19 | 20 | } 21 | public static OfficeInfo Get() 22 | { 23 | String unoPath = ""; 24 | var libreOfficeSubKeyName = @"SOFTWARE\LibreOffice\UNO\InstallPath"; 25 | var openOfficeSubKeyName = @"SOFTWARE\OpenOffice\UNO\InstallPath"; 26 | 27 | // access 32bit registry entry for latest LibreOffice for Current User 28 | Microsoft.Win32.RegistryKey hkcuView32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, Microsoft.Win32.RegistryView.Registry32); 29 | Microsoft.Win32.RegistryKey hkcuUnoInstallPathKey = hkcuView32.OpenSubKey(libreOfficeSubKeyName, false); 30 | 31 | // access 32bit registry entry for latest LibreOffice for Local Machine (All Users) 32 | Microsoft.Win32.RegistryKey hklmView32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32); 33 | Microsoft.Win32.RegistryKey hklmUnoInstallPathKey = hklmView32.OpenSubKey(libreOfficeSubKeyName, false); 34 | if (hkcuUnoInstallPathKey != null && hkcuUnoInstallPathKey.ValueCount > 0) 35 | { 36 | unoPath = (string)hkcuUnoInstallPathKey.GetValue(hkcuUnoInstallPathKey.GetValueNames()[hkcuUnoInstallPathKey.ValueCount - 1]); 37 | } 38 | else 39 | { 40 | 41 | if (hklmUnoInstallPathKey != null && hklmUnoInstallPathKey.ValueCount > 0) 42 | { 43 | unoPath = (string)hklmUnoInstallPathKey.GetValue(hklmUnoInstallPathKey.GetValueNames()[hklmUnoInstallPathKey.ValueCount - 1]); 44 | } 45 | } 46 | if (string.IsNullOrEmpty(unoPath)) 47 | { 48 | hkcuUnoInstallPathKey = hkcuView32.OpenSubKey(openOfficeSubKeyName, false); 49 | hklmUnoInstallPathKey = hklmView32.OpenSubKey(openOfficeSubKeyName, false); 50 | if (hkcuUnoInstallPathKey != null && hkcuUnoInstallPathKey.ValueCount > 0) 51 | { 52 | unoPath = (string)hkcuUnoInstallPathKey.GetValue(hkcuUnoInstallPathKey.GetValueNames()[hkcuUnoInstallPathKey.ValueCount - 1]); 53 | } 54 | else 55 | { 56 | 57 | if (hklmUnoInstallPathKey != null && hklmUnoInstallPathKey.ValueCount > 0) 58 | { 59 | unoPath = (string)hklmUnoInstallPathKey.GetValue(hklmUnoInstallPathKey.GetValueNames()[hklmUnoInstallPathKey.ValueCount - 1]); 60 | } 61 | } 62 | } 63 | 64 | var officeInfo = new OfficeInfo 65 | { 66 | OfficeUnoPath = unoPath, 67 | Kind = string.IsNullOrEmpty(unoPath) ? OfficeKind.Unknown : (unoPath.Contains("LibreOffice") ? OfficeKind.LibreOffice : OfficeKind.OpenOffice) 68 | }; 69 | return officeInfo; 70 | } 71 | 72 | public static bool RunCmd(string workingPath, string cmd, string cmdArguments) 73 | { 74 | var processStartInfo = new ProcessStartInfo(cmd, cmdArguments) 75 | { 76 | WindowStyle = ProcessWindowStyle.Hidden, 77 | CreateNoWindow = true, 78 | UseShellExecute = false, 79 | WorkingDirectory = Path.GetDirectoryName(workingPath), 80 | RedirectStandardInput = true, 81 | RedirectStandardOutput = true, 82 | RedirectStandardError = true 83 | }; 84 | Process p = Process.Start(processStartInfo); 85 | return p.ExitCode == 0; 86 | } 87 | } 88 | public class OfficeInfo 89 | { 90 | public string OfficeUnoPath { get; set; } 91 | public OfficeKind Kind { get; set; } 92 | } 93 | public enum OfficeKind 94 | { 95 | LibreOffice = 0, 96 | OpenOffice = 1, 97 | Unknown = 2, 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | *.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.pfx 193 | *.publishsettings 194 | node_modules/ 195 | orleans.codegen.cs 196 | 197 | # Since there are multiple workflows, uncomment next line to ignore bower_components 198 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 199 | #bower_components/ 200 | 201 | # RIA/Silverlight projects 202 | Generated_Code/ 203 | 204 | # Backup & report files from converting an old project file 205 | # to a newer Visual Studio version. Backup files are not needed, 206 | # because we have git ;-) 207 | _UpgradeReport_Files/ 208 | Backup*/ 209 | UpgradeLog*.XML 210 | UpgradeLog*.htm 211 | 212 | # SQL Server files 213 | *.mdf 214 | *.ldf 215 | 216 | # Business Intelligence projects 217 | *.rdl.data 218 | *.bim.layout 219 | *.bim_*.settings 220 | 221 | # Microsoft Fakes 222 | FakesAssemblies/ 223 | 224 | # GhostDoc plugin setting file 225 | *.GhostDoc.xml 226 | 227 | # Node.js Tools for Visual Studio 228 | .ntvs_analysis.dat 229 | 230 | # Visual Studio 6 build log 231 | *.plg 232 | 233 | # Visual Studio 6 workspace options file 234 | *.opt 235 | 236 | # Visual Studio LightSwitch build output 237 | **/*.HTMLClient/GeneratedArtifacts 238 | **/*.DesktopClient/GeneratedArtifacts 239 | **/*.DesktopClient/ModelManifest.xml 240 | **/*.Server/GeneratedArtifacts 241 | **/*.Server/ModelManifest.xml 242 | _Pvt_Extensions 243 | 244 | # Paket dependency manager 245 | .paket/paket.exe 246 | paket-files/ 247 | 248 | # FAKE - F# Make 249 | .fake/ 250 | 251 | # JetBrains Rider 252 | .idea/ 253 | *.sln.iml 254 | 255 | # CodeRush 256 | .cr/ -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Converter/StreamOpenOfficeDocumentConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.IO; 4 | using NODConverter.OpenOffice.Connection; 5 | using uno; 6 | using unoidl.com.sun.star.frame; 7 | using unoidl.com.sun.star.io; 8 | using unoidl.com.sun.star.lang; 9 | 10 | namespace NODConverter.OpenOffice.Converter 11 | { 12 | /// 13 | /// Alternative stream-based implementation. 14 | ///

15 | /// This implementation passes document data to and from the OpenOffice.org 16 | /// service as streams. 17 | ///

18 | /// Stream-based conversions are slower than the default file-based ones (provided 19 | /// by ) but they allow to run the OpenOffice.org 20 | /// service on a different machine, or under a different system user on the same 21 | /// machine without file permission problems. 22 | ///

23 | /// Warning! There is a bug 24 | /// in OpenOffice.org 2.2.x that causes some input formats, including Word and Excel, not to work when 25 | /// using stream-base conversions. 26 | ///

27 | /// Use this implementation only if is not possible. 28 | ///

29 | /// 30 | public class StreamOpenOfficeDocumentConverter : AbstractOpenOfficeDocumentConverter 31 | { 32 | 33 | public StreamOpenOfficeDocumentConverter(IOpenOfficeConnection connection) 34 | : base(connection) 35 | { 36 | 37 | } 38 | 39 | public StreamOpenOfficeDocumentConverter(IOpenOfficeConnection connection, IDocumentFormatRegistry formatRegistry) 40 | : base(connection, formatRegistry) 41 | { 42 | } 43 | 44 | protected internal override void ConvertInternal(FileInfo inputFile, DocumentFormat inputFormat, FileInfo outputFile, DocumentFormat outputFormat) 45 | { 46 | Stream inputStream = null; 47 | Stream outputStream = null; 48 | try 49 | { 50 | 51 | inputStream = new FileStream(inputFile.FullName, FileMode.Open, FileAccess.Read); 52 | 53 | outputStream = new FileStream(outputFile.FullName, FileMode.Create); 54 | Convert(inputStream, inputFormat, outputStream, outputFormat); 55 | } 56 | catch (FileNotFoundException fileNotFoundException) 57 | { 58 | 59 | throw new ArgumentException(fileNotFoundException.Message); 60 | } 61 | finally 62 | { 63 | if (inputStream != null) inputStream.Close(); 64 | if (outputStream != null) outputStream.Close(); 65 | } 66 | } 67 | 68 | protected internal override void ConvertInternal(Stream inputStream, DocumentFormat inputFormat, Stream outputStream, DocumentFormat outputFormat) 69 | { 70 | IDictionary exportOptions = outputFormat.GetExportOptions(inputFormat.Family); 71 | 72 | try 73 | { 74 | lock (OpenOfficeConnection) 75 | { 76 | LoadAndExport(inputStream, inputFormat.ImportOptions, outputStream, exportOptions); 77 | } 78 | } 79 | catch (OpenOfficeException) 80 | { 81 | throw; 82 | } 83 | 84 | catch (Exception throwable) 85 | { 86 | throw new OpenOfficeException("conversion failed", throwable); 87 | } 88 | } 89 | 90 | /// 91 | /// 92 | /// 93 | /// 94 | /// 95 | /// 96 | /// 97 | /// 98 | private void LoadAndExport(Stream inputStream, IDictionary importOptions, Stream outputStream, IDictionary exportOptions) 99 | { 100 | XComponentLoader desktop = OpenOfficeConnection.Desktop; 101 | 102 | 103 | IDictionary loadProperties = new Hashtable(); 104 | SupportClass.MapSupport.PutAll(loadProperties, DefaultLoadProperties); 105 | SupportClass.MapSupport.PutAll(loadProperties, importOptions); 106 | // doesn't work using InputStreamToXInputStreamAdapter; probably because it's not XSeekable 107 | //property("InputStream", new InputStreamToXInputStreamAdapter(inputStream)) 108 | loadProperties["InputStream"] = new Any(typeof(XInputStream), new XInputStreamWrapper(inputStream)); 109 | 110 | XComponent document = desktop.loadComponentFromURL("private:stream", "_blank", 0, ToPropertyValues(loadProperties)); 111 | if (document == null) 112 | { 113 | throw new OpenOfficeException("conversion failed: input document is null after loading"); 114 | } 115 | 116 | RefreshDocument(document); 117 | 118 | 119 | IDictionary storeProperties = new Hashtable(); 120 | SupportClass.MapSupport.PutAll(storeProperties, exportOptions); 121 | storeProperties["OutputStream"] = new Any(typeof(XOutputStream), new XOutputStreamWrapper(outputStream)); 122 | 123 | try 124 | { 125 | XStorable storable = (XStorable)document; 126 | storable.storeToURL("private:stream", ToPropertyValues(storeProperties)); 127 | } 128 | finally 129 | { 130 | document.dispose(); 131 | } 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /NODConverter.Cli/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using net.sf.dotnetcli; 4 | using NODConverter.OpenOffice.Connection; 5 | using NODConverter.OpenOffice.Converter; 6 | 7 | namespace NODConverter.Cli 8 | { 9 | /// 10 | /// Command line tool to Convert a document into a different format. 11 | ///

12 | /// Usage: can Convert a single file 13 | /// 14 | ///

 15 |     /// ConvertDocument test.odt test.pdf
 16 |     /// 
17 | /// 18 | /// or multiple files at once by specifying the output format 19 | /// 20 | ///
 21 |     /// ConvertDocument -f pdf test1.odt test2.odt
 22 |     /// ConvertDocument -f pdf *.odt
 23 |     /// 
24 | ///
25 | class Program 26 | { 27 | private static readonly Option OptionOutputFormat = new Option("f", "output-format", true, "output format (e.g. pdf)"); 28 | private static readonly Option OptionPort = new Option("p", "port", true, "OpenOffice.org port"); 29 | private static readonly Option OptionVerbose = new Option("v", "verbose", false, "verbose"); 30 | private static readonly Option OptionXmlRegistry = new Option("x", "xml-registry", true, "XML document format registry"); 31 | private static readonly Options Options = InitOptions(); 32 | 33 | private const int ExitCodeConnectionFailed = 1; 34 | //private const int ExitCodeXmlRegistryNotFound = 254; 35 | private const int ExitCodeTooFewArgs = 255; 36 | 37 | private static Options InitOptions() 38 | { 39 | Options options = new Options(); 40 | options.AddOption(OptionOutputFormat); 41 | options.AddOption(OptionPort); 42 | options.AddOption(OptionVerbose); 43 | options.AddOption(OptionXmlRegistry); 44 | return options; 45 | } 46 | [STAThread] 47 | static void Main(string[] arguments) 48 | { 49 | ICommandLineParser commandLineParser = new PosixParser(); 50 | CommandLine commandLine = commandLineParser.Parse(Options, arguments); 51 | 52 | int port = SocketOpenOfficeConnection.DefaultPort; 53 | if (commandLine.HasOption(OptionPort.Opt)) 54 | { 55 | port = Convert.ToInt32(commandLine.GetOptionValue(OptionPort.Opt)); 56 | } 57 | 58 | String outputFormat = null; 59 | if (commandLine.HasOption(OptionOutputFormat.Opt)) 60 | { 61 | outputFormat = commandLine.GetOptionValue(OptionOutputFormat.Opt); 62 | } 63 | 64 | bool verbose = commandLine.HasOption(OptionVerbose.Opt); 65 | 66 | IDocumentFormatRegistry registry = new DefaultDocumentFormatRegistry(); 67 | 68 | String[] fileNames = commandLine.Args; 69 | if ((outputFormat == null && fileNames.Length != 2) || fileNames.Length < 1) 70 | { 71 | String syntax = "Convert [options] input-file output-file; or\n" + "[options] -f output-format input-file [input-file...]"; 72 | HelpFormatter helpFormatter = new HelpFormatter(); 73 | helpFormatter.PrintHelp(syntax, Options); 74 | Environment.Exit(ExitCodeTooFewArgs); 75 | } 76 | 77 | IOpenOfficeConnection connection = new SocketOpenOfficeConnection(port); 78 | OfficeInfo oo = EnvUtils.Get(); 79 | if(oo.Kind == OfficeKind.Unknown) 80 | { 81 | Console.Out.WriteLine("please setup OpenOffice or LibreOffice!"); 82 | return; 83 | } 84 | try 85 | { 86 | if (verbose) 87 | { 88 | Console.Out.WriteLine("-- connecting to OpenOffice.org on port " + port); 89 | } 90 | connection.Connect(); 91 | } 92 | catch (Exception) 93 | { 94 | string CmdArguments = string.Format("-headless -accept=\"socket,host={0},port={1};urp;\" -nofirststartwizard", SocketOpenOfficeConnection.DefaultHost, SocketOpenOfficeConnection.DefaultPort); 95 | if(!EnvUtils.RunCmd(oo.OfficeUnoPath, "soffice", CmdArguments)) 96 | { 97 | Console.Error.WriteLine("ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port " + port + "."); 98 | Environment.Exit(ExitCodeConnectionFailed); 99 | } 100 | 101 | } 102 | try 103 | { 104 | 105 | IDocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry); 106 | if (outputFormat == null) 107 | { 108 | FileInfo inputFile = new FileInfo(fileNames[0]); 109 | FileInfo outputFile = new FileInfo(fileNames[1]); 110 | ConvertOne(converter, inputFile, outputFile, verbose); 111 | } 112 | else 113 | { 114 | foreach (var t in fileNames) 115 | { 116 | var inputFile = new FileInfo(t); 117 | var outputFile = new FileInfo(inputFile.FullName.Remove(inputFile.FullName.LastIndexOf(".", StringComparison.Ordinal)) + "." + outputFormat); 118 | ConvertOne(converter, inputFile, outputFile, verbose); 119 | } 120 | } 121 | } 122 | finally 123 | { 124 | if (verbose) 125 | { 126 | Console.Out.WriteLine("-- disconnecting"); 127 | } 128 | connection.Disconnect(); 129 | } 130 | } 131 | private static void ConvertOne(IDocumentConverter converter, FileInfo inputFile, FileInfo outputFile, bool verbose) 132 | { 133 | if (verbose) 134 | { 135 | Console.Out.WriteLine("-- converting " + inputFile + " to " + outputFile); 136 | } 137 | converter.Convert(inputFile, outputFile); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Connection/AbstractOpenOfficeConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Sockets; 3 | using System.Runtime.CompilerServices; 4 | using Slf; 5 | using uno.util; 6 | using unoidl.com.sun.star.beans; 7 | using unoidl.com.sun.star.bridge; 8 | using unoidl.com.sun.star.connection; 9 | using unoidl.com.sun.star.frame; 10 | using unoidl.com.sun.star.lang; 11 | using unoidl.com.sun.star.ucb; 12 | using unoidl.com.sun.star.uno; 13 | using Exception = System.Exception; 14 | namespace NODConverter.OpenOffice.Connection 15 | { 16 | using Logger = ILogger; 17 | 18 | public abstract class AbstractOpenOfficeConnection : IOpenOfficeConnection, XEventListener 19 | { 20 | 21 | protected internal readonly Logger Logger = LoggerFactory.GetLogger(); 22 | 23 | private readonly string _connectionString; 24 | private XComponent _bridgeComponent; 25 | private XMultiComponentFactory _serviceManager; 26 | private XComponentContext _componentContext; 27 | private XBridge _bridge; 28 | private bool _connected; 29 | private bool _expectingDisconnection; 30 | protected internal AbstractOpenOfficeConnection(string connectionString) 31 | { 32 | _connectionString = connectionString; 33 | } 34 | [MethodImpl(MethodImplOptions.Synchronized)] 35 | public virtual void Connect() 36 | { 37 | Logger.Debug("connecting"); 38 | try 39 | { 40 | EnvUtils.InitUno(); 41 | SocketUtils.Connect(); 42 | //var sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); 43 | XComponentContext localContext = Bootstrap.bootstrap(); 44 | //XComponentContext localContext = Bootstrap.defaultBootstrap_InitialComponentContext(); 45 | XMultiComponentFactory localServiceManager = localContext.getServiceManager(); 46 | XConnector connector = (XConnector)localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext); 47 | XConnection connection = connector.connect(_connectionString); 48 | XBridgeFactory bridgeFactory = (XBridgeFactory)localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext); 49 | _bridge = bridgeFactory.createBridge("", "urp", connection, null); 50 | _bridgeComponent = (XComponent)_bridge; 51 | _bridgeComponent.addEventListener(this); 52 | _serviceManager = (XMultiComponentFactory)_bridge.getInstance("StarOffice.ServiceManager"); 53 | XPropertySet properties = (XPropertySet)_serviceManager; 54 | // Get the default context from the office server. 55 | var oDefaultContext = properties.getPropertyValue("DefaultContext"); 56 | 57 | _componentContext = (XComponentContext)oDefaultContext.Value; 58 | _connected = true; 59 | Logger.Info("connected"); 60 | } 61 | catch (NoConnectException connectException) 62 | { 63 | throw new OpenOfficeException("connection failed: " + _connectionString + ": " + connectException.Message); 64 | } 65 | catch (Exception exception) 66 | { 67 | throw new OpenOfficeException("connection failed: " + _connectionString, exception); 68 | } 69 | } 70 | 71 | [MethodImpl(MethodImplOptions.Synchronized)] 72 | public virtual void Disconnect() 73 | { 74 | SocketUtils.Disconnect(); 75 | Logger.Debug("disconnecting"); 76 | _expectingDisconnection = true; 77 | _bridgeComponent.dispose(); 78 | } 79 | 80 | public virtual bool Connected 81 | { 82 | get 83 | { 84 | return _connected; 85 | } 86 | } 87 | 88 | public virtual void disposing(EventObject @event) 89 | { 90 | _connected = false; 91 | if (_expectingDisconnection) 92 | { 93 | Logger.Info("disconnected"); 94 | } 95 | else 96 | { 97 | Logger.Error("disconnected unexpectedly"); 98 | } 99 | _expectingDisconnection = false; 100 | } 101 | 102 | // for unit tests only 103 | internal virtual void SimulateUnexpectedDisconnection() 104 | { 105 | disposing(null); 106 | _bridgeComponent.dispose(); 107 | } 108 | 109 | private object GetService(string className) 110 | { 111 | try 112 | { 113 | if (!_connected) 114 | { 115 | Logger.Info("trying to (re)connect"); 116 | Connect(); 117 | } 118 | return _serviceManager.createInstanceWithContext(className, _componentContext); 119 | } 120 | catch (Exception exception) 121 | { 122 | throw new OpenOfficeException("could not obtain service: " + className, exception); 123 | } 124 | } 125 | 126 | public virtual XComponentLoader Desktop 127 | { 128 | get 129 | { 130 | return (XComponentLoader)GetService("com.sun.star.frame.Desktop"); 131 | } 132 | } 133 | 134 | public virtual XFileIdentifierConverter FileContentProvider 135 | { 136 | get 137 | { 138 | return (XFileIdentifierConverter)GetService("com.sun.star.ucb.FileContentProvider"); 139 | } 140 | } 141 | 142 | public virtual XBridge Bridge 143 | { 144 | get 145 | { 146 | return _bridge; 147 | } 148 | } 149 | 150 | public virtual XMultiComponentFactory RemoteServiceManager 151 | { 152 | get 153 | { 154 | return _serviceManager; 155 | } 156 | } 157 | 158 | public virtual XComponentContext ComponentContext 159 | { 160 | get 161 | { 162 | return _componentContext; 163 | } 164 | } 165 | 166 | 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Converter/AbstractOpenOfficeDocumentConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.IO; 4 | using NODConverter.OpenOffice.Connection; 5 | using uno; 6 | using unoidl.com.sun.star.beans; 7 | using unoidl.com.sun.star.lang; 8 | using unoidl.com.sun.star.util; 9 | 10 | namespace NODConverter.OpenOffice.Converter 11 | { 12 | public abstract class AbstractOpenOfficeDocumentConverter : IDocumentConverter 13 | { 14 | virtual protected internal IDictionary DefaultLoadProperties 15 | { 16 | get 17 | { 18 | return _defaultLoadProperties; 19 | } 20 | 21 | } 22 | virtual protected internal IDocumentFormatRegistry DocumentFormatRegistry 23 | { 24 | get 25 | { 26 | return _documentFormatRegistry; 27 | } 28 | 29 | } 30 | 31 | 32 | private readonly IDictionary _defaultLoadProperties; 33 | 34 | protected internal IOpenOfficeConnection OpenOfficeConnection; 35 | private readonly IDocumentFormatRegistry _documentFormatRegistry; 36 | 37 | protected AbstractOpenOfficeDocumentConverter(IOpenOfficeConnection connection) 38 | : this(connection, new DefaultDocumentFormatRegistry()) 39 | { 40 | } 41 | 42 | protected AbstractOpenOfficeDocumentConverter(IOpenOfficeConnection openOfficeConnection, IDocumentFormatRegistry documentFormatRegistry) 43 | { 44 | OpenOfficeConnection = openOfficeConnection; 45 | _documentFormatRegistry = documentFormatRegistry; 46 | 47 | 48 | _defaultLoadProperties = new Hashtable(); 49 | _defaultLoadProperties["Hidden"] = true; 50 | _defaultLoadProperties["ReadOnly"] = true; 51 | } 52 | 53 | public virtual void SetDefaultLoadProperty(String name, Object valueRenamed) 54 | { 55 | _defaultLoadProperties[name] = valueRenamed; 56 | } 57 | 58 | public virtual void Convert(FileInfo inputFile, FileInfo outputFile) 59 | { 60 | Convert(inputFile, outputFile, null); 61 | } 62 | 63 | public virtual void Convert(FileInfo inputFile, FileInfo outputFile, DocumentFormat outputFormat) 64 | { 65 | Convert(inputFile, null, outputFile, outputFormat); 66 | } 67 | 68 | public virtual void Convert(Stream inputStream, DocumentFormat inputFormat, Stream outputStream, DocumentFormat outputFormat) 69 | { 70 | EnsureNotNull("inputStream", inputStream); 71 | EnsureNotNull("inputFormat", inputFormat); 72 | EnsureNotNull("outputStream", outputStream); 73 | EnsureNotNull("outputFormat", outputFormat); 74 | ConvertInternal(inputStream, inputFormat, outputStream, outputFormat); 75 | } 76 | 77 | public virtual void Convert(FileInfo inputFile, DocumentFormat inputFormat, FileInfo outputFile, DocumentFormat outputFormat) 78 | { 79 | EnsureNotNull("inputFile", inputFile); 80 | EnsureNotNull("outputFile", outputFile); 81 | 82 | var tmpBool = File.Exists(inputFile.FullName) || Directory.Exists(inputFile.FullName); 83 | if (!tmpBool) 84 | { 85 | throw new ArgumentException("inputFile doesn't exist: " + inputFile); 86 | } 87 | if (inputFormat == null) 88 | { 89 | inputFormat = GuessDocumentFormat(inputFile); 90 | } 91 | if (outputFormat == null) 92 | { 93 | outputFormat = GuessDocumentFormat(outputFile); 94 | } 95 | if (!inputFormat.Importable) 96 | { 97 | throw new ArgumentException("unsupported input format: " + inputFormat.Name); 98 | } 99 | if (!inputFormat.IsExportableTo(outputFormat)) 100 | { 101 | throw new ArgumentException("unsupported conversion: from " + inputFormat.Name + " to " + outputFormat.Name); 102 | } 103 | ConvertInternal(inputFile, inputFormat, outputFile, outputFormat); 104 | } 105 | 106 | protected internal abstract void ConvertInternal(Stream inputStream, DocumentFormat inputFormat, Stream outputStream, DocumentFormat outputFormat); 107 | 108 | protected internal abstract void ConvertInternal(FileInfo inputFile, DocumentFormat inputFormat, FileInfo outputFile, DocumentFormat outputFormat); 109 | 110 | private static void EnsureNotNull(string argumentName, object argumentValue) 111 | { 112 | if (argumentValue == null) 113 | { 114 | throw new ArgumentException(argumentName + " is null"); 115 | } 116 | } 117 | 118 | private DocumentFormat GuessDocumentFormat(FileInfo file) 119 | { 120 | //System.String extension = FilenameUtils.getExtension(file.Name); 121 | //System.String extension = System.IO.Path.GetExtension(file.Name); 122 | String extension = file.Extension.Substring(1); 123 | DocumentFormat format = DocumentFormatRegistry.GetFormatByFileExtension(extension); 124 | if (format == null) 125 | { 126 | throw new ArgumentException("unknown document format for file: " + file); 127 | } 128 | return format; 129 | } 130 | 131 | protected internal virtual void RefreshDocument(XComponent document) 132 | { 133 | XRefreshable refreshable = (XRefreshable)document; 134 | if (refreshable != null) 135 | { 136 | refreshable.refresh(); 137 | } 138 | } 139 | 140 | protected internal static PropertyValue Property(String name, Object valueRenamed) 141 | { 142 | PropertyValue property = new PropertyValue 143 | { 144 | Name = name, 145 | Value = new Any(valueRenamed.GetType(), valueRenamed) 146 | }; 147 | //property.Value = new uno.Any("writer_pdf_Export"); value_Renamed; 148 | return property; 149 | } 150 | 151 | protected internal static PropertyValue[] ToPropertyValues(IDictionary properties) 152 | { 153 | PropertyValue[] propertyValues = new PropertyValue[properties.Count]; 154 | int i = 0; 155 | 156 | for (IEnumerator iter = new SupportClass.HashSetSupport(properties).GetEnumerator(); iter.MoveNext(); ) 157 | { 158 | if (iter.Current != null) 159 | { 160 | DictionaryEntry entry = (DictionaryEntry)iter.Current; 161 | Object valueRenamed = entry.Value; 162 | var renamed = valueRenamed as IDictionary; 163 | if (renamed != null) 164 | { 165 | // recursively Convert nested Map to PropertyValue[] 166 | IDictionary subProperties = renamed; 167 | valueRenamed = ToPropertyValues(subProperties); 168 | } 169 | propertyValues[i++] = Property((String)entry.Key, valueRenamed); 170 | } 171 | } 172 | return propertyValues; 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /NODConverter/DefaultDocumentFormatRegistry.cs: -------------------------------------------------------------------------------- 1 | namespace NODConverter 2 | { 3 | public sealed class DefaultDocumentFormatRegistry : BasicDocumentFormatRegistry 4 | { 5 | 6 | public DefaultDocumentFormatRegistry() 7 | { 8 | 9 | DocumentFormat pdf = new DocumentFormat("Portable Document Format", "application/pdf", "pdf"); 10 | pdf.SetExportFilter(DocumentFamily.Drawing, "draw_pdf_Export"); 11 | pdf.SetExportFilter(DocumentFamily.Presentation, "impress_pdf_Export"); 12 | pdf.SetExportFilter(DocumentFamily.Spreadsheet, "calc_pdf_Export"); 13 | pdf.SetExportFilter(DocumentFamily.Text, "writer_pdf_Export"); 14 | AddDocumentFormat(pdf); 15 | 16 | 17 | DocumentFormat swf = new DocumentFormat("Macromedia Flash", "application/x-shockwave-flash", "swf"); 18 | swf.SetExportFilter(DocumentFamily.Drawing, "draw_flash_Export"); 19 | swf.SetExportFilter(DocumentFamily.Presentation, "impress_flash_Export"); 20 | AddDocumentFormat(swf); 21 | 22 | 23 | DocumentFormat xhtml = new DocumentFormat("XHTML", "application/xhtml+xml", "xhtml"); 24 | xhtml.SetExportFilter(DocumentFamily.Presentation, "XHTML Impress File"); 25 | xhtml.SetExportFilter(DocumentFamily.Spreadsheet, "XHTML Calc File"); 26 | xhtml.SetExportFilter(DocumentFamily.Text, "XHTML Writer File"); 27 | AddDocumentFormat(xhtml); 28 | 29 | // HTML is treated as Text when supplied as input, but as an output it is also 30 | // available for exporting Spreadsheet and Presentation formats 31 | 32 | DocumentFormat html = new DocumentFormat("HTML", DocumentFamily.Text, "text/html", "html"); 33 | html.SetExportFilter(DocumentFamily.Presentation, "impress_html_Export"); 34 | html.SetExportFilter(DocumentFamily.Spreadsheet, "HTML (StarCalc)"); 35 | html.SetExportFilter(DocumentFamily.Text, "HTML (StarWriter)"); 36 | AddDocumentFormat(html); 37 | 38 | 39 | DocumentFormat odt = new DocumentFormat("OpenDocument Text", DocumentFamily.Text, "application/vnd.oasis.opendocument.text", "odt"); 40 | odt.SetExportFilter(DocumentFamily.Text, "writer8"); 41 | AddDocumentFormat(odt); 42 | 43 | 44 | DocumentFormat sxw = new DocumentFormat("OpenOffice.org 1.0 Text Document", DocumentFamily.Text, "application/vnd.sun.xml.writer", "sxw"); 45 | sxw.SetExportFilter(DocumentFamily.Text, "StarOffice XML (Writer)"); 46 | AddDocumentFormat(sxw); 47 | 48 | 49 | DocumentFormat doc = new DocumentFormat("Microsoft Word", DocumentFamily.Text, "application/msword", "doc"); 50 | doc.SetExportFilter(DocumentFamily.Text, "MS Word 97"); 51 | AddDocumentFormat(doc); 52 | 53 | 54 | DocumentFormat docx = new DocumentFormat("Microsoft Word 2007 XML", DocumentFamily.Text, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx"); 55 | AddDocumentFormat(docx); 56 | 57 | 58 | DocumentFormat rtf = new DocumentFormat("Rich Text Format", DocumentFamily.Text, "text/rtf", "rtf"); 59 | rtf.SetExportFilter(DocumentFamily.Text, "Rich Text Format"); 60 | AddDocumentFormat(rtf); 61 | 62 | 63 | DocumentFormat wpd = new DocumentFormat("WordPerfect", DocumentFamily.Text, "application/wordperfect", "wpd"); 64 | AddDocumentFormat(wpd); 65 | 66 | 67 | DocumentFormat txt = new DocumentFormat("Plain Text", DocumentFamily.Text, "text/plain", "txt"); 68 | // default to "Text (encoded)" UTF8,CRLF to prevent OOo from trying to display the "ASCII Filter Options" dialog 69 | txt.SetImportOption("FilterName", "Text (encoded)"); 70 | txt.SetImportOption("FilterOptions", "UTF8,CRLF"); 71 | txt.SetExportFilter(DocumentFamily.Text, "Text (encoded)"); 72 | txt.SetExportOption(DocumentFamily.Text, "FilterOptions", "UTF8,CRLF"); 73 | AddDocumentFormat(txt); 74 | 75 | 76 | DocumentFormat wikitext = new DocumentFormat("MediaWiki wikitext", "text/x-wiki", "wiki"); 77 | wikitext.SetExportFilter(DocumentFamily.Text, "MediaWiki"); 78 | AddDocumentFormat(wikitext); 79 | 80 | 81 | DocumentFormat ods = new DocumentFormat("OpenDocument Spreadsheet", DocumentFamily.Spreadsheet, "application/vnd.oasis.opendocument.spreadsheet", "ods"); 82 | ods.SetExportFilter(DocumentFamily.Spreadsheet, "calc8"); 83 | AddDocumentFormat(ods); 84 | 85 | 86 | DocumentFormat sxc = new DocumentFormat("OpenOffice.org 1.0 Spreadsheet", DocumentFamily.Spreadsheet, "application/vnd.sun.xml.calc", "sxc"); 87 | sxc.SetExportFilter(DocumentFamily.Spreadsheet, "StarOffice XML (Calc)"); 88 | AddDocumentFormat(sxc); 89 | 90 | 91 | DocumentFormat xls = new DocumentFormat("Microsoft Excel", DocumentFamily.Spreadsheet, "application/vnd.ms-excel", "xls"); 92 | xls.SetExportFilter(DocumentFamily.Spreadsheet, "MS Excel 97"); 93 | AddDocumentFormat(xls); 94 | 95 | 96 | DocumentFormat xlsx = new DocumentFormat("Microsoft Excel 2007 XML", DocumentFamily.Spreadsheet, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx"); 97 | AddDocumentFormat(xlsx); 98 | 99 | 100 | DocumentFormat csv = new DocumentFormat("CSV", DocumentFamily.Spreadsheet, "text/csv", "csv"); 101 | csv.SetImportOption("FilterName", "Text - txt - csv (StarCalc)"); 102 | csv.SetImportOption("FilterOptions", "44,34,0"); // Field Separator: ','; Text Delimiter: '"' 103 | csv.SetExportFilter(DocumentFamily.Spreadsheet, "Text - txt - csv (StarCalc)"); 104 | csv.SetExportOption(DocumentFamily.Spreadsheet, "FilterOptions", "44,34,0"); 105 | AddDocumentFormat(csv); 106 | 107 | 108 | DocumentFormat tsv = new DocumentFormat("Tab-separated Values", DocumentFamily.Spreadsheet, "text/tab-separated-values", "tsv"); 109 | tsv.SetImportOption("FilterName", "Text - txt - csv (StarCalc)"); 110 | tsv.SetImportOption("FilterOptions", "9,34,0"); // Field Separator: '\t'; Text Delimiter: '"' 111 | tsv.SetExportFilter(DocumentFamily.Spreadsheet, "Text - txt - csv (StarCalc)"); 112 | tsv.SetExportOption(DocumentFamily.Spreadsheet, "FilterOptions", "9,34,0"); 113 | AddDocumentFormat(tsv); 114 | 115 | 116 | DocumentFormat odp = new DocumentFormat("OpenDocument Presentation", DocumentFamily.Presentation, "application/vnd.oasis.opendocument.presentation", "odp"); 117 | odp.SetExportFilter(DocumentFamily.Presentation, "impress8"); 118 | AddDocumentFormat(odp); 119 | 120 | 121 | DocumentFormat sxi = new DocumentFormat("OpenOffice.org 1.0 Presentation", DocumentFamily.Presentation, "application/vnd.sun.xml.impress", "sxi"); 122 | sxi.SetExportFilter(DocumentFamily.Presentation, "StarOffice XML (Impress)"); 123 | AddDocumentFormat(sxi); 124 | 125 | 126 | DocumentFormat ppt = new DocumentFormat("Microsoft PowerPoint", DocumentFamily.Presentation, "application/vnd.ms-powerpoint", "ppt"); 127 | ppt.SetExportFilter(DocumentFamily.Presentation, "MS PowerPoint 97"); 128 | AddDocumentFormat(ppt); 129 | 130 | 131 | DocumentFormat pptx = new DocumentFormat("Microsoft PowerPoint 2007 XML", DocumentFamily.Presentation, "application/vnd.openxmlformats-officedocument.presentationml.presentation", "pptx"); 132 | AddDocumentFormat(pptx); 133 | 134 | 135 | DocumentFormat odg = new DocumentFormat("OpenDocument Drawing", DocumentFamily.Drawing, "application/vnd.oasis.opendocument.graphics", "odg"); 136 | odg.SetExportFilter(DocumentFamily.Drawing, "draw8"); 137 | AddDocumentFormat(odg); 138 | 139 | 140 | DocumentFormat svg = new DocumentFormat("Scalable Vector Graphics", "image/svg+xml", "svg"); 141 | svg.SetExportFilter(DocumentFamily.Drawing, "draw_svg_Export"); 142 | AddDocumentFormat(svg); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /NODConverter/OpenOffice/Converter/OpenOfficeDocumentConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.IO; 4 | using Dotnet.Commons.IO; 5 | using NODConverter.OpenOffice.Connection; 6 | using Slf; 7 | using unoidl.com.sun.star.frame; 8 | using unoidl.com.sun.star.lang; 9 | using unoidl.com.sun.star.task; 10 | using unoidl.com.sun.star.ucb; 11 | using unoidl.com.sun.star.util; 12 | 13 | namespace NODConverter.OpenOffice.Converter 14 | { 15 | using IOUtils = StreamUtils; 16 | using Logger = ILogger; 17 | 18 | /// 19 | /// Default file-based implementation. 20 | ///

21 | /// This implementation passes document data to and from the OpenOffice.org 22 | /// service as file URLs. 23 | ///

24 | /// File-based conversions are faster than stream-based ones (provided by 25 | /// ) but they require the 26 | /// OpenOffice.org service to be running locally and have the correct 27 | /// permissions to the files. 28 | ///

29 | /// 30 | public class OpenOfficeDocumentConverter : AbstractOpenOfficeDocumentConverter 31 | { 32 | 33 | 34 | private static readonly Logger Logger; 35 | 36 | public OpenOfficeDocumentConverter(IOpenOfficeConnection connection) 37 | : base(connection) 38 | { 39 | } 40 | 41 | public OpenOfficeDocumentConverter(IOpenOfficeConnection connection, IDocumentFormatRegistry formatRegistry) 42 | : base(connection, formatRegistry) 43 | { 44 | } 45 | 46 | /// In this file-based implementation, streams are emulated using temporary files. 47 | protected internal override void ConvertInternal(Stream inputStream, DocumentFormat inputFormat, Stream outputStream, DocumentFormat outputFormat) 48 | { 49 | FileInfo inputFile = null; 50 | FileInfo outputFile = null; 51 | try 52 | { 53 | 54 | inputFile = new FileInfo(string.Format("document.{0}", inputFormat.FileExtension)) 55 | { 56 | Attributes = FileAttributes.Temporary 57 | }; 58 | 59 | Stream inputFileStream = new FileStream(inputFile.FullName, FileMode.Create); 60 | IOUtils.Copy(inputStream, inputFileStream); 61 | 62 | 63 | outputFile = new FileInfo(string.Format("document.{0}", outputFormat.FileExtension)) 64 | { 65 | Attributes = FileAttributes.Temporary 66 | }; 67 | Convert(inputFile, inputFormat, outputFile, outputFormat); 68 | Stream outputFileStream = null; 69 | try 70 | { 71 | 72 | outputFileStream = new FileStream(outputFile.FullName, FileMode.Open, FileAccess.Read); 73 | IOUtils.Copy(outputFileStream, outputStream); 74 | } 75 | finally 76 | { 77 | //IOUtils.closeQuietly(outputFileStream); 78 | if (outputFileStream != null) outputFileStream.Close(); 79 | } 80 | } 81 | catch (IOException ioException) 82 | { 83 | throw new OpenOfficeException("conversion failed", ioException); 84 | } 85 | finally 86 | { 87 | if (inputFile != null) 88 | { 89 | if (File.Exists(inputFile.FullName)) 90 | { 91 | File.Delete(inputFile.FullName); 92 | } 93 | else if (Directory.Exists(inputFile.FullName)) 94 | { 95 | Directory.Delete(inputFile.FullName); 96 | } 97 | } 98 | if (outputFile != null) 99 | { 100 | if (File.Exists(outputFile.FullName)) 101 | { 102 | File.Delete(outputFile.FullName); 103 | } 104 | else if (Directory.Exists(outputFile.FullName)) 105 | { 106 | Directory.Delete(outputFile.FullName); 107 | } 108 | } 109 | } 110 | } 111 | 112 | protected internal override void ConvertInternal(FileInfo inputFile, DocumentFormat inputFormat, FileInfo outputFile, DocumentFormat outputFormat) 113 | { 114 | 115 | IDictionary loadProperties = new Hashtable(); 116 | SupportClass.MapSupport.PutAll(loadProperties, DefaultLoadProperties); 117 | SupportClass.MapSupport.PutAll(loadProperties, inputFormat.ImportOptions); 118 | 119 | IDictionary storeProperties = outputFormat.GetExportOptions(inputFormat.Family); 120 | 121 | lock (OpenOfficeConnection) 122 | { 123 | XFileIdentifierConverter fileContentProvider = OpenOfficeConnection.FileContentProvider; 124 | String inputUrl = fileContentProvider.getFileURLFromSystemPath("", inputFile.FullName); 125 | String outputUrl = fileContentProvider.getFileURLFromSystemPath("", outputFile.FullName); 126 | 127 | LoadAndExport(inputUrl, loadProperties, outputUrl, storeProperties); 128 | } 129 | } 130 | 131 | private void LoadAndExport(String inputUrl, IDictionary loadProperties, String outputUrl, IDictionary storeProperties) 132 | { 133 | XComponent document; 134 | try 135 | { 136 | document = LoadDocument(inputUrl, loadProperties); 137 | } 138 | catch (ErrorCodeIOException errorCodeIoException) 139 | { 140 | throw new OpenOfficeException("conversion failed: could not load input document; OOo errorCode: " + errorCodeIoException.ErrCode, errorCodeIoException); 141 | } 142 | catch (Exception otherException) 143 | { 144 | throw new OpenOfficeException("conversion failed: could not load input document", otherException); 145 | } 146 | if (document == null) 147 | { 148 | throw new OpenOfficeException("conversion failed: could not load input document"); 149 | } 150 | 151 | try 152 | { 153 | RefreshDocument(document); // xls to pdf, Exception:Unable to cast transparent proxy to type 'unoidl.com.sun.star.util.XRefreshable'. 154 | } 155 | catch 156 | { 157 | // ignored 158 | } 159 | 160 | try 161 | { 162 | storeDocument(document, outputUrl, storeProperties); 163 | } 164 | catch (ErrorCodeIOException errorCodeIoException) 165 | { 166 | throw new OpenOfficeException("conversion failed: could not save output document; OOo errorCode: " + errorCodeIoException.ErrCode, errorCodeIoException); 167 | } 168 | catch (Exception otherException) 169 | { 170 | throw new OpenOfficeException("conversion failed: could not save output document", otherException); 171 | } 172 | } 173 | 174 | private XComponent LoadDocument(String inputUrl, IDictionary loadProperties) 175 | { 176 | XComponentLoader desktop = OpenOfficeConnection.Desktop; 177 | //PropertyValue[] propertyValue2 = new PropertyValue[1]; 178 | //PropertyValue aProperty = new PropertyValue(); 179 | //aProperty.Name = "Hidden"; 180 | //aProperty.Value = new uno.Any(true); 181 | //propertyValue2[0] = aProperty; 182 | ToPropertyValues(loadProperties); 183 | return desktop.loadComponentFromURL(inputUrl, "_blank", 0, ToPropertyValues(loadProperties));//toPropertyValues(loadProperties) 184 | } 185 | 186 | private void storeDocument(XComponent document, String outputUrl, IDictionary storeProperties) 187 | { 188 | try 189 | { 190 | XStorable storable = (XStorable)document; 191 | storable.storeToURL(outputUrl, ToPropertyValues(storeProperties)); 192 | } 193 | finally 194 | { 195 | XCloseable closeable = (XCloseable)document; 196 | if (closeable != null) 197 | { 198 | try 199 | { 200 | closeable.close(true); 201 | } 202 | catch (CloseVetoException closeVetoException) 203 | { 204 | Logger.Warn("document.close() vetoed:"+closeVetoException.Message); 205 | } 206 | } 207 | else 208 | { 209 | document.dispose(); 210 | } 211 | } 212 | } 213 | static OpenOfficeDocumentConverter() 214 | { 215 | Logger = LoggerFactory.GetLogger(); 216 | } 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /NODConverter/SupportClass.cs: -------------------------------------------------------------------------------- 1 | // 2 | // In order to Convert some functionality to Visual C#, the Java Language Conversion Assistant 3 | // creates "support classes" that duplicate the original functionality. 4 | // 5 | // Support classes replicate the functionality of the original code, but in some cases they are 6 | // substantially different architecturally. Although every effort is made to preserve the 7 | // original architecture of the application in the converted project, the user should be aware that 8 | // the primary goal of these support classes is to replicate functionality, and that at times 9 | // the architecture of the resulting solution may differ somewhat. 10 | // 11 | 12 | using System; 13 | using System.Linq; 14 | 15 | namespace NODConverter 16 | { 17 | /// 18 | /// Contains conversion support elements such as classes, interfaces and static methods. 19 | /// 20 | public class SupportClass 21 | { 22 | /// 23 | /// SupportClass for the HashSet class. 24 | /// 25 | [Serializable] 26 | public class HashSetSupport : System.Collections.ArrayList, ISetSupport 27 | { 28 | public HashSetSupport() 29 | { 30 | } 31 | 32 | public HashSetSupport(System.Collections.ICollection c) 33 | { 34 | AddAll(c); 35 | } 36 | 37 | public HashSetSupport(int capacity) 38 | : base(capacity) 39 | { 40 | } 41 | 42 | /// 43 | /// Adds a new element to the ArrayList if it is not already present. 44 | /// 45 | /// Element to insert to the ArrayList. 46 | /// Returns true if the new element was inserted, false otherwise. 47 | new public virtual bool Add(object obj) 48 | { 49 | bool inserted; 50 | 51 | if ((inserted = Contains(obj)) == false) 52 | { 53 | base.Add(obj); 54 | } 55 | 56 | return !inserted; 57 | } 58 | 59 | /// 60 | /// Adds all the elements of the specified collection that are not present to the list. 61 | /// 62 | /// Collection where the new elements will be added 63 | /// Returns true if at least one element was added, false otherwise. 64 | public bool AddAll(System.Collections.ICollection c) 65 | { 66 | System.Collections.IEnumerator e = new System.Collections.ArrayList(c).GetEnumerator(); 67 | bool added = false; 68 | 69 | while (e.MoveNext()) 70 | { 71 | if (Add(e.Current)) 72 | added = true; 73 | } 74 | 75 | return added; 76 | } 77 | 78 | /// 79 | /// Returns a copy of the HashSet instance. 80 | /// 81 | /// Returns a shallow copy of the current HashSet. 82 | public override object Clone() 83 | { 84 | return MemberwiseClone(); 85 | } 86 | } 87 | 88 | 89 | /*******************************/ 90 | /// 91 | /// Represents a collection ob objects that contains no duplicate elements. 92 | /// 93 | public interface ISetSupport : System.Collections.IList 94 | { 95 | /// 96 | /// Adds a new element to the Collection if it is not already present. 97 | /// 98 | /// The object to add to the collection. 99 | /// Returns true if the object was added to the collection, otherwise false. 100 | new bool Add(object obj); 101 | 102 | /// 103 | /// Adds all the elements of the specified collection to the Set. 104 | /// 105 | /// Collection of objects to add. 106 | /// true 107 | bool AddAll(System.Collections.ICollection c); 108 | } 109 | 110 | 111 | /*******************************/ 112 | /// 113 | /// Provides functionality not found in .NET map-related interfaces. 114 | /// 115 | public class MapSupport 116 | { 117 | /// 118 | /// Determines whether the SortedList contains a specific value. 119 | /// 120 | /// The dictionary to check for the value. 121 | /// The object to locate in the SortedList. 122 | /// Returns true if the value is contained in the SortedList, false otherwise. 123 | public static bool ContainsValue(System.Collections.IDictionary d, object obj) 124 | { 125 | bool contained; 126 | var type = d.GetType(); 127 | 128 | //Classes that implement the SortedList class 129 | if (type == Type.GetType("System.Collections.SortedList")) 130 | { 131 | contained = ((System.Collections.SortedList)d).ContainsValue(obj); 132 | } 133 | //Classes that implement the Hashtable class 134 | else if (type == Type.GetType("System.Collections.Hashtable")) 135 | { 136 | contained = ((System.Collections.Hashtable)d).ContainsValue(obj); 137 | } 138 | else 139 | { 140 | //Reflection. Invoke "containsValue" method for proprietary classes 141 | System.Reflection.MethodInfo method = type.GetMethod("containsValue"); 142 | contained = (bool)method.Invoke(d, new[] { obj }); 143 | } 144 | 145 | return contained; 146 | } 147 | 148 | 149 | /// 150 | /// Determines whether the NameValueCollection contains a specific value. 151 | /// 152 | /// The dictionary to check for the value. 153 | /// The object to locate in the SortedList. 154 | /// Returns true if the value is contained in the NameValueCollection, false otherwise. 155 | public static bool ContainsValue(System.Collections.Specialized.NameValueCollection d, object obj) 156 | { 157 | bool contained = false; 158 | 159 | for (int i = 0; i < d.Count && !contained; i++) 160 | { 161 | var values = d.GetValues(i); 162 | if (values != null) 163 | { 164 | if (values.Any(val => val.Equals(obj))) 165 | { 166 | contained = true; 167 | } 168 | } 169 | } 170 | return contained; 171 | } 172 | 173 | /// 174 | /// Copies all the elements of d to target. 175 | /// 176 | /// Collection where d elements will be copied. 177 | /// Elements to copy to the target collection. 178 | public static void PutAll(System.Collections.IDictionary target, System.Collections.IDictionary d) 179 | { 180 | if (d != null) 181 | { 182 | System.Collections.ArrayList keys = new System.Collections.ArrayList(d.Keys); 183 | System.Collections.ArrayList values = new System.Collections.ArrayList(d.Values); 184 | 185 | for (int i = 0; i < keys.Count; i++) 186 | target[keys[i]] = values[i]; 187 | } 188 | } 189 | 190 | /// 191 | /// Returns a portion of the list whose keys are less than the limit object parameter. 192 | /// 193 | /// The list where the portion will be extracted. 194 | /// The end element of the portion to extract. 195 | /// The portion of the collection whose elements are less than the limit object parameter. 196 | public static System.Collections.SortedList HeadMap(System.Collections.SortedList l, object limit) 197 | { 198 | System.Collections.Comparer comparer = System.Collections.Comparer.Default; 199 | System.Collections.SortedList newList = new System.Collections.SortedList(); 200 | 201 | for (int i = 0; i < l.Count; i++) 202 | { 203 | if (comparer.Compare(l.GetKey(i), limit) >= 0) 204 | break; 205 | 206 | newList.Add(l.GetKey(i), l[l.GetKey(i)]); 207 | } 208 | 209 | return newList; 210 | } 211 | 212 | /// 213 | /// Returns a portion of the list whose keys are greater that the lowerLimit parameter less than the upperLimit parameter. 214 | /// 215 | /// The list where the portion will be extracted. 216 | /// The start element of the portion to extract. 217 | /// The end element of the portion to extract. 218 | /// The portion of the collection. 219 | public static System.Collections.SortedList SubMap(System.Collections.SortedList list, object lowerLimit, object upperLimit) 220 | { 221 | System.Collections.Comparer comparer = System.Collections.Comparer.Default; 222 | System.Collections.SortedList newList = new System.Collections.SortedList(); 223 | 224 | if (list != null) 225 | { 226 | if ((list.Count > 0) && (!(lowerLimit.Equals(upperLimit)))) 227 | { 228 | int index = 0; 229 | while (comparer.Compare(list.GetKey(index), lowerLimit) < 0) 230 | index++; 231 | 232 | for (; index < list.Count; index++) 233 | { 234 | if (comparer.Compare(list.GetKey(index), upperLimit) >= 0) 235 | break; 236 | 237 | newList.Add(list.GetKey(index), list[list.GetKey(index)]); 238 | } 239 | } 240 | } 241 | 242 | return newList; 243 | } 244 | 245 | /// 246 | /// Returns a portion of the list whose keys are greater than the limit object parameter. 247 | /// 248 | /// The list where the portion will be extracted. 249 | /// The start element of the portion to extract. 250 | /// The portion of the collection whose elements are greater than the limit object parameter. 251 | public static System.Collections.SortedList TailMap(System.Collections.SortedList list, object limit) 252 | { 253 | System.Collections.Comparer comparer = System.Collections.Comparer.Default; 254 | System.Collections.SortedList newList = new System.Collections.SortedList(); 255 | 256 | if (list != null) 257 | { 258 | if (list.Count > 0) 259 | { 260 | int index = 0; 261 | while (comparer.Compare(list.GetKey(index), limit) < 0) 262 | index++; 263 | 264 | for (; index < list.Count; index++) 265 | newList.Add(list.GetKey(index), list[list.GetKey(index)]); 266 | } 267 | } 268 | 269 | return newList; 270 | } 271 | } 272 | 273 | 274 | /*******************************/ 275 | /// 276 | /// Deserializes an object, or an entire graph of connected objects, and returns the object intance 277 | /// 278 | /// Reader instance used to read the object 279 | /// The object instance 280 | public static object Deserialize(System.IO.BinaryReader binaryReader) 281 | { 282 | System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); 283 | return formatter.Deserialize(binaryReader.BaseStream); 284 | } 285 | 286 | /*******************************/ 287 | /// 288 | /// Writes an object to the specified Stream 289 | /// 290 | /// The target Stream 291 | /// The object to be sent 292 | public static void Serialize(System.IO.Stream stream, object objectToSend) 293 | { 294 | System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); 295 | formatter.Serialize(stream, objectToSend); 296 | } 297 | 298 | /// 299 | /// Writes an object to the specified BinaryWriter 300 | /// 301 | /// The target BinaryWriter 302 | /// The object to be sent 303 | public static void Serialize(System.IO.BinaryWriter binaryWriter, object objectToSend) 304 | { 305 | System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); 306 | formatter.Serialize(binaryWriter.BaseStream, objectToSend); 307 | } 308 | 309 | } 310 | } 311 | --------------------------------------------------------------------------------