public override void Convert(string src, string dest, out string msg)
        {
            msg = null;
            try
            {
                if (string.IsNullOrEmpty(src))
                {
                    msg = "源文件不能为空";
                    return;
                }
                var contentType = MimeTypes.GetContentType(src);
                if (contentType != "application/mspowerpoint")
                {
                    msg = "源文件应为powerpoint文件";
                    return;
                }
                if (string.IsNullOrEmpty(dest))
                {
                    msg = "目标路径不能为空";
                    return;
                }
                if (!File.Exists(src))
                {
                    msg = "文件不存在";
                    return;
                }

                if (IsPasswordProtected(src))
                {
                    msg = "存在密码";
                    return;
                }

                app           = new Microsoft.Office.Interop.PowerPoint.Application();
                presentations = app.Presentations;
                presentation  = presentations.Open(src.ToString(), Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                presentation.ExportAsFixedFormat(dest.ToString(), Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF);
                // presentation.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, "", false, false, false, false, false, null);
            }
            catch (Exception e)
            {
                release();
                throw new ConvertException(e.Message);
            }
            release();
        }
示例#2
0
        private Boolean ConvertPowerpoint(string path, string newpath)
        {
            Boolean returnB = true;

            Microsoft.Office.Interop.PowerPoint.Application  pptApplication  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = null;

            object unknownType = Type.Missing;

            pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            try
            {
                pptPresentation = pptApplication.Presentations.Open(path,
                                                                    Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue,
                                                                    Microsoft.Office.Core.MsoTriState.msoFalse);

                pptPresentation.ExportAsFixedFormat(newpath,
                                                    Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF,
                                                    Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint,
                                                    MsoTriState.msoFalse, Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,
                                                    Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null,
                                                    Microsoft.Office.Interop.PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true,
                                                    true, false, unknownType);

                if (pptPresentation == null)
                {
                    MainForm.error = String.Format("Filename {0} - Unexpected error at ConvertPowerpoint \r\n", Path.GetFileName(path));
                    returnB        = false;
                }
            }
            catch (Exception ex)
            {
                MainForm.error = String.Format("Filename {0} - {1} at ConvertPowerpoint \r\n", Path.GetFileName(path), ex.Message);
                returnB        = false;
            }
            pptPresentation.Close();
            pptPresentation = null;
            pptApplication.Quit();
            pptApplication = null;
            return(returnB);
        }
示例#3
0
        public bool ExportPptFileToPdf(string workbookPath, string outputPath)
        {
            Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = null;

            Microsoft.Office.Interop.PowerPoint.Application appWord = new Microsoft.Office.Interop.PowerPoint.Application();
            try
            {
                pptPresentation = appWord.Presentations.Open(workbookPath,
                                                             Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue,
                                                             Microsoft.Office.Core.MsoTriState.msoFalse);
                pptPresentation.ExportAsFixedFormat(outputPath,
                                                    Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF,
                                                    Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint,
                                                    MsoTriState.msoFalse, Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,
                                                    Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null,
                                                    Microsoft.Office.Interop.PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true,
                                                    true, false);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                // Close and release the Document object.
                if (pptPresentation != null)
                {
                    pptPresentation.Close();
                    pptPresentation = null;
                }

                // Quit PowerPoint and release the ApplicationClass object.
                if (appWord != null)
                {
                    appWord.Quit();
                    appWord = null;
                }
            }
        }
示例#4
0
        public static bool OfficePPTToPDF(string sourcePath, string targetPath)
        {
            bool result = false;

            Microsoft.Office.Interop.PowerPoint.Application  application = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation document    = null;
            try
            {
                document = application.Presentations.Open(sourcePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
                document.ExportAsFixedFormat(targetPath, Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF);
                result = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = false;
            }
            finally
            {
                document.Close();
            }
            return(result);
        }