/// <summary>
        /// Sets the conversion type (html,doc,rtf)
        /// </summary>
        /// <param name="p_convertFrom">ConvertFrom value from the command file</param>
        /// <param name="p_convertTo">ConverTo value from the command file</param>
        /// <param name="p_fileName">the command file</param>
        private void setConversionType(string p_convertFrom, string p_convertTo,
                                       string p_fileName)
        {
            string baseFileName = p_fileName.Substring(
                0, p_fileName.Length - FILE_EXT_LEN);

            m_originalFileName = baseFileName + p_convertFrom.ToLower();

            if (p_convertTo.Equals(HTML))
            {
                m_newFormatType = PowerPoint_Class.PpSaveAsFileType.ppSaveAsHTML;
                m_newFileName   = baseFileName + HTML;
            }
            else if (p_convertTo.Equals(PPT))
            {
                m_newFormatType = PowerPoint_Class.PpSaveAsFileType.ppSaveAsPresentation;
                m_newFileName   = baseFileName + PPT;
            }
            else if (p_convertTo.Equals(PPTX))
            {
                m_newFormatType = PowerPoint_Class.PpSaveAsFileType.ppSaveAsOpenXMLPresentation;
                m_newFileName   = baseFileName + PPTX;
            }
            else if (p_convertTo.Equals(PDF))
            {
                m_newFormatType = PowerPoint_Class.PpSaveAsFileType.ppSaveAsPDF;
                m_newFileName   = baseFileName + PDF;
            }
        }
Пример #2
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

            string      sourceFileName = inputFilePath;
            MsoTriState openReadonly   = MsoTriState.msoTrue;
            MsoTriState untitled       = MsoTriState.msoFalse;
            MsoTriState withWindow     = MsoTriState.msoFalse;

            PowerPoint.Presentation presentation = this._application.Presentations.Open(sourceFileName, openReadonly, untitled, withWindow);

            string targetFileName = outputFilePath;

            PowerPoint.PpSaveAsFileType saveFormat = (PowerPoint.PpSaveAsFileType)format.SaveFormat;
            MsoTriState embedTrueTypeFonts         = MsoTriState.msoTriStateMixed;

            presentation.SaveAs(targetFileName, saveFormat, embedTrueTypeFonts);

            presentation.Close();

            this._application.AutomationSecurity = originalAutomationSecurity;
        }
Пример #3
0
        public void PPTSave(string filePath)
        {
            try
            {
                filePath = filePath.Replace('/', '\\');
                if (filePath.Equals(m_PptPresSet.FullName))
                {
                    m_PptPresSet.Save();
                }
                else
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    POWERPOINT.PpSaveAsFileType format = POWERPOINT.PpSaveAsFileType.ppSaveAsDefault;
                    m_PptPresSet.SaveAs(filePath, format, Microsoft.Office.Core.MsoTriState.msoFalse);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
    public void exportPPT()
    {
        string path;                           //文件路径变量

        PPT.Application pptApp;                //Excel应用程序变量

        PPT.Presentation pptDoc;               //Excel文档变量

        path = @"D:\MyPPT.ppt";                //路径

        pptApp = new PPT.ApplicationClass();   //初始化

        //如果已存在,则删除

        if (File.Exists((string)path))

        {
            File.Delete((string)path);
        }

        //由于使用的是COM库,因此有许多变量需要用Nothing代替

        Object Nothing = Missing.Value;

        pptDoc = pptApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);

        pptDoc.Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);

        string pic = @"D:\1.png";

        foreach (PPT.Slide slide in pptDoc.Slides)

        {
            slide.Shapes.AddPicture(pic, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 150, 150, 300, 200);
        }



        //WdSaveFormat为PPTs文档的保存格式

        PPT.PpSaveAsFileType format = PPT.PpSaveAsFileType.ppSaveAsDefault;

        //将 pptDoc文档对象的内容保存为XLSX文档

        pptDoc.SaveAs(path, format, Microsoft.Office.Core.MsoTriState.msoFalse);

        //关闭pptDoc文档对象

        pptDoc.Close();

        //关闭pptApp组件对象

        pptApp.Quit();

        Console.WriteLine(path + " 创建完毕!");

        // Console.ReadLine();
    }
Пример #5
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

            string tempFilePath = Converter.GetTempFileName(".pptx");

            if (this.Options.UseAddin && Path.GetExtension(inputFilePath) == ".odp")
            {
                // convert odp to pptx
                this.ConvertWithOdfConverter(inputFilePath, tempFilePath);
                inputFilePath = tempFilePath;
            }

            string      sourceFileName = inputFilePath;
            MsoTriState openReadonly   = MsoTriState.msoTrue;
            MsoTriState untitled       = MsoTriState.msoFalse;
            MsoTriState withWindow     = MsoTriState.msoFalse;

            PowerPoint.Presentation presentation = this._application.Presentations.Open(sourceFileName, openReadonly, untitled, withWindow);

            string targetFileName = outputFilePath;

            PowerPoint.PpSaveAsFileType saveFormat = (PowerPoint.PpSaveAsFileType)format.SaveFormat;
            MsoTriState embedTrueTypeFonts         = MsoTriState.msoTriStateMixed;

            string tempFilePath2 = Converter.GetTempFileName(".pptx");

            if (this.Options.UseAddin && format.SaveFormat == (int)PowerPoint.PpSaveAsFileType.ppSaveAsOpenDocumentPresentation)
            {
                // export to odt using addin
                saveFormat = PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation;
                string tempOpenXmlDocument = tempFilePath2;
                presentation.SaveAs(tempOpenXmlDocument, saveFormat, embedTrueTypeFonts);
                presentation.Close();

                this.ConvertWithOdfConverter(tempFilePath2, outputFilePath);
            }
            else
            {
                presentation.SaveAs(targetFileName, saveFormat, embedTrueTypeFonts);
                presentation.Close();
            }

            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
            if (File.Exists(tempFilePath2))
            {
                File.Delete(tempFilePath2);
            }
            this._application.AutomationSecurity = originalAutomationSecurity;
        }
Пример #6
0
        /// <summary>
        /// Save a PowerPoint presentation
        /// </summary>
        /// <param name="presentationToSave">Handle to PPT.Presentation object to save</param>
        /// <param name="pathAndFileName">Path (including filename) of where to save the presentation</param>
        /// <param name="fileType">PPT.PpSaveAsFileType object</param>
        /// <param name="embedTrueTypeFonts">Whether to embed TrueType fonts</param>
        public void SavePresentationAs(
            PPT.Presentation presentationToSave,
            string pathAndFileName,
            PPT.PpSaveAsFileType fileType,
            bool embedTrueTypeFonts)
        {
            if (embedTrueTypeFonts)
            {
                presentationToSave.SaveAs(pathAndFileName, fileType, OFFICE.MsoTriState.msoTrue);
                return;
            }

            presentationToSave.SaveAs(pathAndFileName, fileType, OFFICE.MsoTriState.msoFalse);
        }
Пример #7
0
        /// <summary>
        /// 转换函数
        /// </summary>
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="savePath">保存的路径</param>
        /// <returns></returns>
        public bool Convert(string sourcePath, string savePath)
        {
            bool result = false;

            PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            try
            {
                pptApplication = new PowerPoint.ApplicationClass();
                presentation   = pptApplication.Presentations.Open(sourcePath,
                                                                   MsoTriState.msoTrue,
                                                                   MsoTriState.msoFalse,
                                                                   MsoTriState.msoFalse);
                presentation.SaveAs(savePath, targetFileType, MsoTriState.msoTrue);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    presentation = null;
                }

                if (pptApplication != null)
                {
                    pptApplication.Quit();
                    pptApplication = null;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            return(result);
        }
Пример #8
0
    /// <summary>
    /// 把PowerPoing文件转换成PDF格式文件
    /// </summary>
    /// <param name="sourcePath">源文件路径</param>
    /// <param name="targetPath">目标文件路径</param>
    /// <returns>true=转换成功</returns>
    private bool PPTConvertToPDF(string sourcePath, string targetPath)
    {
        bool result = false;

        //string er = "";
        PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
        object missing = Type.Missing;

        PowerPoint.ApplicationClass application  = null;
        PowerPoint.Presentation     persentation = null;
        try
        {
            application  = new PowerPoint.ApplicationClass();
            persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
            persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
            result = true;
            //er = "1";
        }
        catch (Exception ex)
        {
            //er= ex.Message.ToString();
            result = false;
        }
        finally
        {
            if (persentation != null)
            {
                persentation.Close();
                persentation = null;
            }
            if (application != null)
            {
                application.Quit();
                application = null;
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        return(result);
    }
Пример #9
0
        /// <summary>
        /// 把PowerPoing文件转换成PDF格式文件
        /// </summary>
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PPTConvertToPDF(string sourcePath, string targetPath)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            targetPath = HttpContext.Current.Server.MapPath(targetPath);
            bool result;

            PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            PowerPoint.ApplicationClass application  = null;
            PowerPoint.Presentation     persentation = null;
            try
            {
                application  = new PowerPoint.ApplicationClass();
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
Пример #10
0
        /// <summary>
        /// 把PowerPoing文件转换成PDF格式文件
        /// </summary>
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PPTConvertToPDF(string sourcePath, string targetPath)
        {
            bool result;

            PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            PowerPoint.ApplicationClass application  = null;
            PowerPoint.Presentation     persentation = null;
            try
            {
                application  = new PowerPoint.ApplicationClass();
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                //Logger.WriteLog("Service Error:PowerPoing转pdf" + ex.ToString(), "Log\\ServiceInfoError.txt", true);
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
Пример #11
0
        ///<summary>把PowerPoint文件转换成PDF格式文件</summary>
        ///<param name="sourcePath">源文件路径</param>
        ///<param name="targetPath">目标文件路径</param>
        ///<returns>true=转换成功</returns>
        public static bool PPt2Pdf(string sourcePath, string targetPath)
        {
            bool result;

            PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            //object missing = Type.Missing;
            PowerPoint.ApplicationClass application  = null;
            PowerPoint.Presentation     persentation = null;
            try
            {
                string source = sourcePath;
                string target = targetPath;
                application  = new PowerPoint.ApplicationClass();
                persentation = application.Presentations.Open(source, MsoTriState.msoTrue
                                                              , MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(target
                                    , targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                throw ex;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
        /// <summary>
        /// PPT 2 PDF
        /// </summary>
        /// <param name="sourcePath">源路径</param>
        /// <param name="targetPath">目标路径</param>
        /// <returns></returns>
        public static bool PptToPNG(string sourcePath, string targetPath)
        {
            bool result;

            PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPNG;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.Application application = null;
            PowerPoint.Presentation persentation = null;
            try
            {
                application  = new Microsoft.Office.Interop.PowerPoint.Application();
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
Пример #13
0
        static void Main(string[] args)
        {
            string path;             //文件路径变量

            PPT.Application  pptApp; //Excel应用程序变量
            PPT.Presentation pptDoc; //Excel文档变量

            PPT.Presentation pptDoctmp;



            path   = @"C:\MyPPT.ppt";            //路径
            pptApp = new PPT.ApplicationClass(); //初始化

            //如果已存在,则删除
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }

            //由于使用的是COM库,因此有许多变量需要用Nothing代替
            Object Nothing = Missing.Value;

            pptDoc = pptApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
            pptDoc.Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText);

            string text = "示例文本";

            foreach (PPT.Slide slide in pptDoc.Slides)
            {
                foreach (PPT.Shape shape in slide.Shapes)
                {
                    shape.TextFrame.TextRange.InsertAfter(text);
                }
            }


            //WdSaveFormat为Excel文档的保存格式
            PPT.PpSaveAsFileType format = PPT.PpSaveAsFileType.ppSaveAsDefault;

            //将excelDoc文档对象的内容保存为XLSX文档
            pptDoc.SaveAs(path, format, Microsoft.Office.Core.MsoTriState.msoFalse);

            //关闭excelDoc文档对象
            pptDoc.Close();

            //关闭excelApp组件对象
            pptApp.Quit();

            Console.WriteLine(path + " 创建完毕!");

            Console.ReadLine();


            string pathHtml = @"c:\MyPPT.html";

            PPT.Application pa = new PPT.ApplicationClass();

            pptDoctmp = pa.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            PPT.PpSaveAsFileType formatTmp = PPT.PpSaveAsFileType.ppSaveAsHTML;
            pptDoctmp.SaveAs(pathHtml, formatTmp, Microsoft.Office.Core.MsoTriState.msoFalse);
            pptDoctmp.Close();
            pa.Quit();
            Console.WriteLine(pathHtml + " 创建完毕!");
        }
Пример #14
0
        /// <summary>
        /// 把每张幻灯片转换成图片
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <param name="targetPath"></param>
        /// <param name="targetFileType"></param>
        public void ConvertPics(string sourcePath, string picOutPath, int totalWidth, int height, int space, POWERPOINT.PpSaveAsFileType targetFileType = POWERPOINT.PpSaveAsFileType.ppSaveAsJPG, string type = "JPG")
        {
            int width = (totalWidth - space) / 2;

            //   persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);//整个ppt的文件转换为其他的格式
            objPresSet.Slides[1].Export(picOutPath + "1." + type, type, totalWidth, 440); //将ppt中的某张转换为图片文件
            for (int i = 2; i < objPresSet.Slides.Count + 1; i++)
            {
                try
                {
                    if (!Convert.ToBoolean((objPresSet.Slides.Count - 1) % 2))
                    {
                        objPresSet.Slides[i].Export(picOutPath + i + "." + type, type, width, height); //将ppt中的某张转换为图片文件
                    }
                    else
                    {
                        if (i == objPresSet.Slides.Count)
                        {
                            objPresSet.Slides[i].Export(picOutPath + i + "." + type, type, totalWidth, 440);
                        }
                        else
                        {
                            objPresSet.Slides[i].Export(picOutPath + i + "." + type, type, width, height);
                        }
                    }
                }
                catch (Exception ex) { }
            }

            //persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); //整个ppt的文件转换为其他的格式
        }
Пример #15
0
        private void button2_Click(object sender, EventArgs e)
        {
            string path;                    //文件路径变量

            PowerPoint.Application  pptApp; //Excel应用程序变量
            PowerPoint.Presentation pptDoc; //Excel文档变量

            PowerPoint.Presentation pptDoctmp;



            path = @"C:\Users\ssor\Desktop\test.ppt";      //路径

            /*
             * pptApp = new PowerPoint.ApplicationClass(); //初始化
             *
             * //如果已存在,则删除
             * if (File.Exists((string)path))
             * {
             *  File.Delete((string)path);
             * }
             *
             * //由于使用的是COM库,因此有许多变量需要用Nothing代替
             * Object Nothing = Missing.Value;
             * pptDoc = pptApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
             * pptDoc.Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText);
             *
             * string text = "示例文本";
             *
             * foreach (PowerPoint.Slide slide in pptDoc.Slides)
             * {
             *  foreach (PowerPoint.Shape shape in slide.Shapes)
             *  {
             *      shape.TextFrame.TextRange.InsertAfter(text);
             *  }
             * }
             *
             *
             * //WdSaveFormat为Excel文档的保存格式
             * PowerPoint.PpSaveAsFileType format = PowerPoint.PpSaveAsFileType.ppSaveAsDefault;
             *
             * //将excelDoc文档对象的内容保存为XLSX文档
             * pptDoc.SaveAs(path, format, Microsoft.Office.Core.MsoTriState.msoFalse);
             *
             * //关闭excelDoc文档对象
             * pptDoc.Close();
             *
             * //关闭excelApp组件对象
             * pptApp.Quit();
             *
             * //Console.WriteLine(path + " 创建完毕!");
             *
             * //Console.ReadLine();
             *
             * return;
             * */

            string pathHtml = @"C:\Users\ssor\Desktop\MyPPT.html";

            PowerPoint.Application pa = new PowerPoint.ApplicationClass();

            pptDoctmp = pa.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            PowerPoint.PpSaveAsFileType formatTmp = PowerPoint.PpSaveAsFileType.ppSaveAsHTMLDual;
            pptDoctmp.SaveAs(pathHtml, formatTmp, Microsoft.Office.Core.MsoTriState.msoFalse);
            pptDoctmp.Close();
            pa.Quit();
            MessageBox.Show("创建完毕!");
            //Console.WriteLine(pathHtml + " 创建完毕!");
        }
Пример #16
0
 public FormatInfo(string name, string description, string defaultFileExtension, PowerPoint.PpSaveAsFileType saveFormat)
 {
     _name                 = name;
     _description          = description;
     _defaultFileExtension = defaultFileExtension;
     _saveFormat           = (int)saveFormat;
 }