Example #1
0
        public void CloseOpenOffice()
        {
            var ps = Process.GetProcessesByName("soffice.bin");

            foreach (var process in ps)
            {
                Logger.DebugFormat("Closing openoffice pid: {0}", process.Id);
                process.Kill();
            }

            ps = Process.GetProcessesByName(_config.GetPathToLibreOffice());
            foreach (var process in ps)
            {
                Logger.DebugFormat("Closing openoffice pid: {0}", process.Id);
                process.Kill();
            }
        }
Example #2
0
        public LibreOfficeUnoConversion(JobsHostConfiguration config)
        {
            //Needed by UNO SDK5.
            //http://stackoverflow.com/questions/31856025/bootstrap-uno-api-libreoffice-exception
            //look at comments of funbit. We need to set UNO_PATH and soffice should be in the PATH
            //of the system.
            var sofficePath = config.GetPathToLibreOffice();
            var unoPath     = Path.GetDirectoryName(sofficePath);

            Environment.SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process);

            _config = config;
            Logger  = NullLogger.Instance;
        }
        public string Run(string sourceFile, string outType)
        {
            Logger.DebugFormat("DIRECT SOFFICE.EXE CONVERSION: Starting conversion of blobId {0} to {1}", sourceFile, outType);
            string pathToLibreOffice = _config.GetPathToLibreOffice();
            var    outputFile        = Path.ChangeExtension(sourceFile, outType);

            string arguments = string.Format("--headless -convert-to {2} -outdir \"{0}\"  \"{1}\" ",
                                             Path.GetDirectoryName(sourceFile),
                                             sourceFile,
                                             outType
                                             );

            var psi = new ProcessStartInfo(pathToLibreOffice, arguments)
            {
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Minimized
            };

            Logger.DebugFormat("Command: {0} {1}", pathToLibreOffice, arguments);

            using (var p = Process.Start(psi))
            {
                Logger.Debug("Process started");
                p.WaitForExit();
                Logger.Debug("Process ended");
            }

            if (!File.Exists(outputFile))
            {
                throw new Exception("Conversion failed");
            }

            return(outputFile);
        }