Esempio n. 1
0
        public void ToPdf(WordToPdfData wtp)
        {
            //获取libreoffice命令的路径
            string libreOfficePath = getLibreOfficePath();

            ProcessStartInfo procStartInfo = new ProcessStartInfo(libreOfficePath, string.Format("--convert-to pdf --outdir {0} --nologo {1}", wtp.Targetpdf, wtp.Sourcedocx));

            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute        = false;
            procStartInfo.CreateNoWindow         = true;
            procStartInfo.WorkingDirectory       = Environment.CurrentDirectory;

            //开启线程
            Process process = new Process()
            {
                StartInfo = procStartInfo,
            };

            process.Start();
            process.WaitForExit();

            if (process.ExitCode != 0)
            {
                throw new LibreOfficeFailedException(process.ExitCode);
            }
        }
Esempio n. 2
0
        public void WToPdf(WordToPdfData wtp)
        {
            ////建立 word application instance
            Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
            ////打开 word 文档
            var wordDocument = appWord.Documents.Open(wtp.Sourcedocx);

            ////转 PDF, 会自动创建同名的PDF格式文件
            wordDocument.ExportAsFixedFormat(wtp.Targetpdf, WdExportFormat.wdExportFormatPDF);
            ////关闭 word 文档
            wordDocument.Close();
            appWord.Quit();
        }
Esempio n. 3
0
        public HttpResponseMessage WToP(WordToPdfData wtp)
        {
            try
            {
                WordToPDFHandle wordToPdfDataHandle = new WordToPDFHandle();
                wordToPdfDataHandle.WToPdf(wtp);
            }
            catch (Exception ex)
            {
                return(tool.MsgFormat(ResponseCode.操作失败, "转换失败", ex.ToString()));
            }

            return(tool.MsgFormat(ResponseCode.成功, "转换成功", "0"));
        }