private void release()
        {
            if (presentation != null)
            {
                try
                {
                    presentation.Close();
                    releaseCOMObject(presentation);
                }
                catch (Exception e)
                {
                }
            }

            if (app != null)
            {
                try
                {
                    app.Quit();
                    releaseCOMObject(app);
                }
                catch (Exception e)
                {
                }
            }
        }
Exemple #2
0
    protected override void printWorker()
    {
        try
        {
            isPrinting       = true;
            officePowerPoint = new Microsoft.Office.Interop.PowerPoint.Application();
            officePowerPoint.DisplayAlerts = Microsoft.Office.Interop.PowerPoint.PpAlertLevel.ppAlertsNone;
            Microsoft.Office.Interop.PowerPoint.Presentation doc = null;
            doc = officePowerPoint.Presentations.Open(
                filename,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoFalse,
                Microsoft.Office.Core.MsoTriState.msoFalse);
            doc.PrintOptions.ActivePrinter     = printer;
            doc.PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse;
            doc.PrintOptions.OutputType        = Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputSlides;
            doc.PrintOut();
            System.Threading.Thread.Sleep(500);
            doc.Close();
            Marshal.FinalReleaseComObject(doc);
            doc           = null;
            workerPrintOk = true;
            isPrinting    = true;
        }
        catch (System.Exception ex)
        {
            isPrinting = false;

            Logging.Log("Unable to print PowerPoint file " + filename + ". Exception: " + ex.Message, Logging.LogLevel.Error);
            workerPrintOk = false;
        }
    }
Exemple #3
0
        /// <summary>
        /// PPT转成Html
        /// </summary>
        /// <param name="physicalPath">文件物理路径 绝对路径</param>
        /// <param name="serverPath">文件服务器路径 相对路径</param>
        /// <returns></returns>
        public static OfficeResult PPTToHtml(string physicalPath, string serverPath)
        {
            OfficeResult res = new OfficeResult();

            try
            {
                //-------------------------------------------------
                Microsoft.Office.Interop.PowerPoint.Application  ppApp   = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(physicalPath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                string htmlName   = Path.GetFileNameWithoutExtension(physicalPath) + ".html";
                string outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;
                prsPres.SaveAs(outputFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
                prsPres.Close();
                ppApp.Quit();
                //---------------------------------------------------------------
                //return Path.GetDirectoryName(System.Web.HttpContext.Current.Server.UrlDecode(url)) + "\\" + htmlName;
                string previewFile = Path.GetDirectoryName(serverPath) + "\\" + htmlName;
                res.code    = 1;
                res.message = previewFile;
                return(res);
            }
            catch (Exception ex)
            {
                res.code    = 0;
                res.message = ex.Message;
                return(res);
            }
        }
        public static void PptToHtmlFile(string PptFilePath)
        {
            //获得html文件名

            string htmlFileName = PptFilePath.Substring(0, PptFilePath.LastIndexOf(".")) + ".html";

            Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();

            Microsoft.Office.Interop.PowerPoint.Presentation pptFile = null;

            try
            {
                //打开一个ppt文件

                pptFile = ppt.Presentations.Open(PptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue,

                                                 Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);

                //转换成html格式

                pptFile.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,

                               Microsoft.Office.Core.MsoTriState.msoCTrue);
            }

            finally
            {
                if (pptFile != null)
                {
                    pptFile.Close();
                }
                ppt.Quit();
                GC.Collect();
            }
        }
Exemple #5
0
        /// <summary>把Word文件转换成为PDF格式文件</summary>   
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PowerPointToHtml(string sourcePath, string targetPath)
        {
            bool result = false;

            try
            {
                //Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.;
                Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Core.MsoTriState m1 = new MsoTriState();
                Microsoft.Office.Core.MsoTriState m2 = new MsoTriState();
                Microsoft.Office.Core.MsoTriState m3 = new MsoTriState();
                Microsoft.Office.Interop.PowerPoint.Presentation pp = ppt.Presentations.Open(sourcePath, m1, m2, m3);
                pp.SaveAs(targetPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
                pp.Close();
                ppt.Quit();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(false);
            }
        }
Exemple #6
0
        private void btnConvertAll_Click(object sender, EventArgs e)
        {
            progressBar1.Visible = true;
            progressBar1.Maximum = listBoxFiles.Items.Count;
            progressBar1.Step    = 1;
            Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
            foreach (object logListItem in listBoxFiles.Items)
            {
                progressBar1.PerformStep();
                this.Refresh();

                string strLogName      = logListItem.ToString();
                string strFullFilePath = textBoxFolder.Text + "\\" + strLogName;

                if (File.Exists(strFullFilePath + ".ppt"))
                {
                    Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApp.Presentations.Open(strFullFilePath + ".ppt", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                    pptPresentation.SaveAs(strFullFilePath + ".pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPicturePresentation);
                    pptPresentation.Close();
                }
            }
            pptApp.Quit();
            progressBar1.Visible = false;
        }
        /// <summary>
        ///     The convert to pptx.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="targetLanguage">The target language.</param>
        /// <returns>
        ///     The System.String.
        /// </returns>
        private static string ConvertToPptx(string fullPath, string targetLanguage)
        {
            LoggingManager.LogMessage("Converting the document " + fullPath + " from ppt to pptx.");

            object file2 = GetOutputDocumentFullName(fullPath, targetLanguage);

            Microsoft.Office.Interop.PowerPoint.Application powerPointApp =
                new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                Microsoft.Office.Interop.PowerPoint.Presentation presentation =
                    powerPointApp.Presentations.Open(
                        fullPath,
                        MsoTriState.msoFalse,
                        MsoTriState.msoFalse,
                        MsoTriState.msoFalse);

                presentation.SaveAs(
                    file2.ToString(),
                    Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
                    MsoTriState.msoTriStateMixed);
                presentation.Close();
            }
            finally
            {
                powerPointApp.Quit();
            }

            LoggingManager.LogMessage("Converted the document " + fullPath + " from ppt to pptx.");
            return(file2.ToString());
        }
 public void Close()
 {
     if (presentation != null)
     {
         presentation.Close();
         slides       = null;
         presentation = null;
     }
 }
 public void SaveAs(string filename)
 {
     if (File.Exists(filename))
     {
         File.Delete(filename);
     }
     _presentation.SaveAs(filename);
     _presentation.Close();
     _powerPoint.Quit();
 }
        /// <summary>
           /// ppt convert to html
           /// </summary>
           /// <param name="path">要转换的文档的路径</param>
           /// <param name="savePath">转换成的html的保存路径</param>
           /// <param name="wordFileName">转换后html文件的名字</param>
        public static void PPTToHtml(string path, string savePath, string wordFileName)
        {
            Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
            string strSourceFile      = path;
            string strDestinationFile = savePath + wordFileName + ".html";

            Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(strSourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
            prsPres.Close();
            ppApp.Quit();
        }
Exemple #11
0
        private Boolean unlockPowerPoint(String r_password, String w_password)
        {
            Boolean NOPASS = true;

            /////////////////////////////////////////////////////
            // PwerPoint解錠
            /////////////////////////////////////////////////////
            if (avaPoawrPoint)
            {
                try {
                    pptPre = pptPres.Open(dataGridView1.Rows[0].Cells[3].Value.ToString() + ":: :: ",
                                          MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
                } catch {
                    NOPASS = false;
                }

                if (NOPASS)
                {
                    // パスワードがかかっていない
                    label2.Text = WindowsFormsApplication1.Properties.Resources.powerpoint2;
                    // "This presentation is not applied password.";
                    return(false);
                }
                else
                {
                    String rp = (r_password.Length == 0) ? ":: " : "::" + r_password;
                    String wp = (w_password.Length == 0) ? ":: " : "::" + w_password;

                    try {
                        pptPre = pptPres.Open(dataGridView1.Rows[0].Cells[3].Value.ToString() + rp + wp,
                                              Microsoft.Office.Core.MsoTriState.msoFalse,
                                              Microsoft.Office.Core.MsoTriState.msoFalse,
                                              Microsoft.Office.Core.MsoTriState.msoFalse);
                    } catch {
                        label2.Text = WindowsFormsApplication1.Properties.Resources.message2;
                        //"Password is incorrect.";
                        return(false);
                    }

                    pptPre.Password      = null;
                    pptPre.WritePassword = null;
                    try {
                        pptPre.Save();
                    } catch (Exception eX) {
                        label2.Text = WindowsFormsApplication1.Properties.Resources.error1 + eX.Message;
                        // "Saving failed." + eX.Message;
                        return(false);
                    }
                    pptPre.Close();
                }
            }
            return(true);
        }
Exemple #12
0
        private void ConvertFile(string strFilePath)
        {
            if (File.Exists(strFilePath + ".ppt"))
            {
                Microsoft.Office.Interop.PowerPoint.Application  pptApp          = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApp.Presentations.Open(strFilePath + ".ppt", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                pptPresentation.SaveAs(strFilePath + ".pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPicturePresentation);
                pptPresentation.Close();

                pptApp.Quit();
            }
        }
Exemple #13
0
        public override bool PPT2HTML(string sourcePath, string targetPath, string targetRelativeDirectory)
        {
            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.Application  pptApp       = null;
            Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
            try
            {
                if (!sourcePath.EndsWith(".ppt") && !sourcePath.EndsWith(".pptx"))
                {
                    return(false);
                }

                if (File.Exists(targetPath))
                {
                    File.Delete(targetPath);
                }
                object target = targetPath;
                pptApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                Microsoft.Office.Interop.PowerPoint.Presentations presentations = pptApp.Presentations;

                presentation = presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                presentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
            }
            catch (Exception e)
            {
                Log.LogInfo("ppt转换html:", e);
                return(false);
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    presentation = null;
                }
                if (pptApp != null)
                {
                    pptApp.Quit();
                    pptApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            pptHelper(targetPath, targetRelativeDirectory);

            return(true);
        }
        static void Main(string[] args)
        {
            string strPath =
                System.AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/");

            // Instantiate Object
            APServer.Server server = new APServer.Server();

            // Path and filename of output
            server.NewDocumentName = "Server.PowerPointPrinting.pdf";
            server.OutputDirectory = strPath;

            // Start the print job
            ServerDK.Results.ServerResult result = server.BeginPrintToPDF();
            if (result.ServerStatus == ServerDK.Results.ServerStatus.Success)
            {
                // Automate PowerPoint to print a document to activePDF Server
                // NOTE: You must add the 'Microsoft PowerPoint
                // <<version number>> Object Library' COM object as a reference
                // to your .NET application to access the PowerPoint Object.
                Microsoft.Office.Interop.PowerPoint._Application oPPT =
                    new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation oPRES =
                    oPPT.Presentations.Open(
                        $"{strPath}Server.PowerPoint.Input.pptx",
                        Microsoft.Office.Core.MsoTriState.msoTrue,
                        Microsoft.Office.Core.MsoTriState.msoFalse,
                        Microsoft.Office.Core.MsoTriState.msoFalse);
                Microsoft.Office.Interop.PowerPoint.PrintOptions objOptions =
                    oPRES.PrintOptions;
                objOptions.ActivePrinter     = server.NewPrinterName;
                objOptions.PrintInBackground = 0;
                oPRES.PrintOut(1, 9999, "", 1, 0);
                oPRES.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
                oPRES.Close();
                oPPT.Quit();

                // Wait(seconds) for job to complete
                result = server.EndPrintToPDF(waitTime: 30);
            }

            // Output result
            WriteResult(result);

            // Process Complete
            Console.WriteLine("Done!");
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
        ///<summary>
        /// 把PowerPoint文件转换成PDF格式文件
        ///</summary>
        ///<param name="sourcePath">源文件路径(物理路径)</param>
        ///<param name="targetPath">目标文件路径(物理路径)</param>
        ///<returns>true=转换成功</returns>
        public static bool PPTConvertToPDF(string sourcePath, string targetPath)
        {
            bool result;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation     persentation = null;
            try
            {
                application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                //打开
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                if (persentation != null)
                {
                    //写入
                    persentation.SaveAs(targetPath, targetFileType, 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);
        }
Exemple #16
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);
        }
Exemple #17
0
        /// <summary> 把PowerPoint文件转换成PDF格式文件</summary>   
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>   
        public static bool PowerPointToBMP(string sourcePath, string targetPath)
        {
            bool result = false;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsBMP;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null; Microsoft.Office.Interop.PowerPoint.Presentation persentation = null;
            try
            {
                application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                //application.Visible = MsoTriState.msoFalse;
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, MsoTriState.msoTrue);
                result = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                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);
        }
Exemple #18
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;
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Powerpoint转PDF文档。
        /// </summary>
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns></returns>
        public static bool ConvertPowerPointToPDF(string sourcePath, string targetPath)
        {
            bool   result = false;
            object miss   = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            Microsoft.Office.Interop.PowerPoint.Presentation     present    = null;
            Microsoft.Office.Interop.PowerPoint.Application      app        = null;
            try
            {
                app     = new Microsoft.Office.Interop.PowerPoint.Application();
                present = app.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                present.SaveAs(targetPath, targetType, Microsoft.Office.Core.MsoTriState.msoTrue);
                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                throw ex;
            }
            finally
            {
                if (present != null)
                {
                    present.Close();
                    present = null;
                }
                if (app != null)
                {
                    app.Quit();
                    app = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
Exemple #20
0
        private Boolean lockPowerPoint(String r_password, String w_password)
        {
            ////////////////////////////////////////////////////
            // PowerPoint施錠
            ////////////////////////////////////////////////////
            if (avaPoawrPoint)
            {
                // パスワードが設定されているかチェック
                try {
                    pptPre = pptPres.Open(dataGridView1.Rows[0].Cells[3].Value.ToString() + ":: :: ",
                                          Microsoft.Office.Core.MsoTriState.msoFalse,
                                          Microsoft.Office.Core.MsoTriState.msoFalse,
                                          Microsoft.Office.Core.MsoTriState.msoFalse);
                } catch {
                    label2.Text = WindowsFormsApplication1.Properties.Resources.powerpoint1;
                    // "This presentation has been password-protected.";
                    return(false);
                }

                if (textBox1.Text.Length > 0)
                {
                    pptPre.Password = r_password;
                }
                if (textBox2.Text.Length > 0)
                {
                    pptPre.WritePassword = w_password;
                }
                try {
                    pptPre.Save();
                } catch (Exception eX) {
                    label2.Text = WindowsFormsApplication1.Properties.Resources.error1 + eX.Message;
                    // "Saving failed." + eX.Message;
                    return(false);
                }
                pptPre.Close();
            }
            return(true);
        }
        private void PPTToPDF(string path, string extend)
        {
            string filePath = HttpContext.Current.Server.MapPath(path);
            string outPath  = HttpContext.Current.Server.MapPath(path).Replace(extend, ".pdf");

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation     presentation = null;
            try
            {
                application  = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                presentation = application.Presentations.Open(filePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                presentation.SaveAs(outPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);

                Utils.StringToTxt("UploadHandler.ashx=>PPTToPDF:成功");
            }
            catch (Exception ex)
            {
                Utils.StringToTxt("UploadHandler.ashx=>PPTToPDF:失败。" + ex.Message);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    presentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Exemple #22
0
        /// <summary>
        /// ppt转成Html
        /// </summary>
        /// <param name="excelPath">要转换的文档的路径</param>
        /// <param name="htmlPath">转换成html的保存路径</param>
        /// <returns>是否成功</returns>
        public static bool PptToHtml(string filePath, string htmlPath = null)
        {
            var flg = false;

            Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();

            string strDestinationFile = htmlPath ?? System.IO.Path.ChangeExtension(filePath, ".html");

            Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(filePath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            try
            {
                prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
                flg = true;
            }
            catch (Exception ex) { throw ex; }
            try
            {
                prsPres.Close();
                ppApp.Quit();
            }
            catch { }
            return(flg);
        }
Exemple #23
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);
        }
Exemple #24
0
        private static void GetPowerPointData(Microsoft.Office.Interop.PowerPoint.Presentation presen)
        {
            //ファイル名の出力
            Console.WriteLine("file:" + presen.FullName);

            Microsoft.Office.Interop.PowerPoint.Slides AllSlide = presen.Slides;
            Microsoft.Office.Interop.PowerPoint.Slide  slide    = AllSlide[1];
            Microsoft.Office.Interop.PowerPoint.Shapes shapes   = slide.Shapes;

            foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in shapes)
            {
                string title = shape.TextFrame.TextRange.Text;
                title = title.Replace("\r", "");
                //文字列の出力
                Console.WriteLine(title);
            }
            Console.WriteLine();

            if (SaveImage)
            {
                SaveSlideImage(presen);
            }
            presen.Close();
        }
Exemple #25
0
        public override bool Parse(FileInfo sourceFile, DirectoryInfo targetDir)
        {
            int index = 1;

            if (!IsTargetFileOutdated(sourceFile, BuildTargetFileName(sourceFile, targetDir, index)))
            {
                // if the first slide of a file is not invalid all other slides are still valid, too
                return(false);
            }
            Microsoft.Office.Interop.PowerPoint.Application powerpoint = powerpointTL.Value;
            if (powerpoint == null)
            {
                powerpoint = new Microsoft.Office.Interop.PowerPoint.Application();

                powerpointTL.Value = powerpoint;
            }
            Microsoft.Office.Interop.PowerPoint.Presentation ppt = powerpointTL.Value.Presentations.Open(sourceFile.FullName, MsoTriState.msoTrue,
                                                                                                         MsoTriState.msoTrue, MsoTriState.msoFalse);
            try
            {
                foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in ppt.Slides)
                {
                    DoExport(sourceFile, targetDir, index, delegate(FileInfo targetFile)
                    {
                        slide.Export(targetFile.FullName, "png", 1024, 768);
                    });
                    index++;
                }
                return(true);
            }
            finally
            {
                ppt.Saved = MsoTriState.msoTrue;
                ppt.Close();
            }
        }
Exemple #26
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            lblMessage.Enabled = false;
            lblMessage.Text    = "Parsing..";
            var result = this.folderBrowser.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }
            var folderPath = FileIO.GetPath(folderBrowser.SelectedPath);

            var ext = new List <string> {
                ".ppt", ".pptx"
            };
            var presos = Directory.GetFiles(folderPath, "*.*", SearchOption.TopDirectoryOnly)
                         .Where(s => ext.Any(x => s.EndsWith(x))).ToList();

            var pdfext = new List <string> {
                ".pdf"
            };
            var pdfs = Directory.GetFiles(folderPath, "*.*", SearchOption.TopDirectoryOnly)
                       .Where(s => pdfext.Any(x => s.EndsWith(x))).ToList();

            if (presos.Count() == 0 && pdfs.Count() == 0)
            {
                lblMessage.Text = "no presentations or Pdfs found";
                return;
            }

            var tempDir = Directory.CreateDirectory(folderPath + @"\_temp");

            Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = null;
            if (presos.Count() != 0)
            {
                try
                {
                    PowerPoint_App = PowerPointEx.ConvertToPPTX(presos, tempDir.FullName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error initializing, close Powerpoint if it is open");
                    return;
                }
            }

            Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;

            string outFile = "";


            foreach (var preso in presos)
            {
                Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(preso, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                var pptName = Path.GetFileName(preso);

                var underscoreIndex = pptName.IndexOf('_');
                var newPptName      = pptName.Remove(0, underscoreIndex + 1);

                if (string.IsNullOrEmpty(outFile))
                {
                    outFile  = Path.GetFileNameWithoutExtension(newPptName);
                    outFile += ".docx";
                    var outDir = Directory.CreateDirectory(folderPath + @"\_output");
                    _fullFilePath = Path.Combine(outDir.FullName, outFile);
                    WordEx.CreateDoc(_fullFilePath);
                }

                WordEx.AddTitle(newPptName);


                foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in presentation.Slides)
                {
                    bool firstLine = true;

                    //ParseWithOpenXML(slideId,preso);
                    string pptx     = Path.GetFileNameWithoutExtension(preso) + ".pptx";
                    string pptxFile = Path.Combine(tempDir.FullName, pptx);
                    _slideInfos.Add(new SlideInfo()
                    {
                        Id = slide.SlideNumber, path = pptxFile
                    });

                    var prevNoteText = "";
                    foreach (var item in slide.Shapes)
                    {
                        //firstLine = true;
                        var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;

                        if (shape.HasTextFrame == MsoTriState.msoTrue)
                        {
                            if (shape.TextFrame2.HasText == MsoTriState.msoTrue)
                            {
                                if (shape.TextFrame2.TextRange.ParagraphFormat.Bullet.Type != MsoBulletType.msoBulletNone)
                                {
                                    List <string> bullets = new List <string>();
                                    foreach (TextRange2 para in shape.TextFrame2.TextRange.Paragraphs)
                                    {
                                        bullets.Add(para.Text);
                                        //var bulletText = "- " + para.Text;
                                        //buffer.AppendLine(bulletText);
                                    }
                                    WordEx.AddBulletList(bullets);
                                    //string text = shape.TextFrame2.TextRange.Text;
                                    //WordEx.AddBulletList(text);
                                }
                                else
                                {
                                    var text = shape.TextFrame2.TextRange.Text;
                                    //slideText += text + " ";
                                    //buffer.AppendLine(text);
                                    if (firstLine)
                                    {
                                        WordEx.AddHeader(text);
                                        firstLine = false;
                                    }
                                    else
                                    {
                                        WordEx.AddText(text);
                                    }
                                }
                            }
                            else if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                            {
                                var text = shape.TextFrame.TextRange.Text;
                                //slideText += text + " ";
                                //buffer.AppendLine(text);
                                if (firstLine)
                                {
                                    WordEx.AddHeader(text);
                                    firstLine = false;
                                }
                                else
                                {
                                    WordEx.AddText(text);
                                }
                            }

                            firstLine = false;
                        }

                        if (slide.HasNotesPage == MsoTriState.msoTrue)
                        {
                            //bool processedNotes = false;

                            foreach (var note in slide.NotesPage.Shapes)
                            {
                                //if (processedNotes)
                                //    break;

                                var noteShape = (Microsoft.Office.Interop.PowerPoint.Shape)note;

                                if (noteShape.HasTextFrame == MsoTriState.msoTrue)
                                {
                                    if (noteShape.TextFrame2.HasText == MsoTriState.msoTrue)
                                    {
                                        var text1 = noteShape.TextFrame2.TextRange.Text;
                                        if (text1 == prevNoteText || WordEx.IsNumeric(text1))
                                        {
                                            continue;
                                        }

                                        //processedNotes = true; //go to next since notes are duplicated in interop.
                                        if (noteShape.TextFrame2.TextRange.ParagraphFormat.Bullet.Type != MsoBulletType.msoBulletNone)
                                        {
                                            List <string> bullets = new List <string>();
                                            foreach (TextRange2 para in noteShape.TextFrame2.TextRange.Paragraphs)
                                            {
                                                bullets.Add(para.Text);
                                            }
                                            WordEx.AddBulletList(bullets, true);
                                            prevNoteText = noteShape.TextFrame2.TextRange.Text;
                                        }
                                        else
                                        {
                                            var text = noteShape.TextFrame2.TextRange.Text;

                                            WordEx.AddText(text, true);
                                        }
                                    }
                                    else if (noteShape.TextFrame.HasText == MsoTriState.msoTrue)
                                    {
                                        var text = noteShape.TextFrame.TextRange.Text;

                                        WordEx.AddText(text, true);
                                    }
                                }
                            }
                        }
                    }
                }
                presentation.Close();
                //var presoSource = Path.GetFileName(preso);
                //string processedPreso = Path.Combine(processedDir.FullName, presoSource);
                //if (!File.Exists(processedPreso))
                //    File.Copy(preso, processedPreso);
            }
            try
            {
                PowerPointEx.Close(PowerPoint_App);
                AddImages();

                AddPdfs(pdfs, tempDir.FullName);

                WordEx.Save();

                lblMessage.Text    = "Created Doc: " + _fullFilePath;
                lblMessage.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public static void PrintDiscountCoupon(string companyName, string discountProductName, string discountValueOnProduct)
        {
            int    copiesToPrint         = 1;
            string printTemplateFileName = @"\Assets\Docs\PrinterReceipt.pptx";
            string qrCodeImageName       = @"\Assets\Images\QREncode.jpg";
            string printFileName         = @"\Assets\Docs\printReceipt.pptx";
            string printTemplateFilePath = Helper.GetAssetURI(printTemplateFileName);
            string qrCodeImagepath       = Helper.GetAssetURI(qrCodeImageName);
            string printReceiptFilePath  = Helper.GetAssetURI(printFileName);

            Microsoft.Office.Interop.PowerPoint.Presentation work = null;
            Microsoft.Office.Interop.PowerPoint.Application  app  = new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                if (File.Exists(printReceiptFilePath))
                {
                    File.Delete(printReceiptFilePath);
                }
                if (File.Exists(qrCodeImagepath))
                {
                    File.Delete(qrCodeImagepath);
                }

                Microsoft.Office.Interop.PowerPoint.Presentations presprint = app.Presentations;
                work = presprint.Open(printTemplateFilePath, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
                work.PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse;
                Microsoft.Office.Interop.PowerPoint.Slide slide = work.Slides[1];
                foreach (var item in slide.Shapes)
                {
                    var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;

                    if (shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            var textRange = shape.TextFrame.TextRange;
                            var text      = textRange.Text;
                            if (text.Contains("10%"))
                            {
                                text = text.Replace("10", discountValueOnProduct);
                                shape.TextFrame.TextRange.Text = text;
                            }
                            else if (text.Contains("Microsoft"))
                            {
                                text = text.Replace("Microsoft", companyName);
                                shape.TextFrame.TextRange.Text = text;
                            }
                            else if (text.Contains("Windows Phone 8"))
                            {
                                text = text.Replace("Windows Phone 8", discountProductName);
                                shape.TextFrame.TextRange.Text = text;
                            }
                        }
                    }
                    else
                    {
                        if (shape.Name.ToString() == "Picture 2")
                        {
                            shape.Delete();
                            //Add QRCode to print
                            RippleCommonUtilities.HelperMethods.GenerateQRCode("http://projectripple.azurewebsites.net/Ripple.aspx", qrCodeImagepath);
                            slide.Shapes.AddPicture(qrCodeImagepath, MsoTriState.msoFalse, MsoTriState.msoTrue, 560, 90, 80, 80);
                        }
                    }
                }

                work.SaveAs(printReceiptFilePath);
                work.PrintOut();
                work.Close();
                app.Quit();

                //delete the PrintReceipt File
                File.Delete(printReceiptFilePath);
                //Delete the QRCOde image
                File.Delete(qrCodeImagepath);
            }
            catch (System.Exception ex)
            {
                work.Close();
                app.Quit();
                //delete the PrintReceipt File
                File.Delete(printReceiptFilePath);
                //Delete the QRCOde image
                File.Delete(qrCodeImagepath);
                RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in  Print Discount Coupon at Screen side: {0}", ex.Message);
            }
        }
Exemple #28
0
        public string ExportOffer(DataSet data)
        {
            throw new Exception("Export to power point is underconstruction!");
#pragma warning disable CS0162 // Unreachable code detected
            lock (PowerpointController.Powerpoint2013LockObject)
#pragma warning restore CS0162 // Unreachable code detected
            {
                try
                {
                    DataTable dtOfferPrintoutPP_View = data.Tables["OfferMng_OfferPrintoutPP_View"];
                    DataRow   drOfferPrintoutPP_View = dtOfferPrintoutPP_View.Rows[0];

                    DataTable dtOfferPrintoutPP_Detail_View = data.Tables["OfferMng_OfferPrintoutPP_Detail_View"];

                    DataTable dtOfferPrintoutPP_PieceDetail_View = data.Tables["OfferMng_OfferPrintoutPP_PieceDetail_View"];

                    // init power point
                    Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();

                    // Create the presentation ~ hit new button in powerpoint
                    Microsoft.Office.Interop.PowerPoint.Presentation presentation = app.Presentations.Add();

                    //Add Slide 1
                    var slide1 = presentation.Slides.AddSlide(presentation.Slides.Count + 1, presentation.SlideMaster.CustomLayouts[1]);
                    slide1.Layout = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank;

                    try
                    {
                        //Add logo
                        slide1.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "eurofar-logo.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)37.5, (float)25.5);

                        //Add logo 2
                        slide1.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "thumbnail/" + drOfferPrintoutPP_View["ClientLogoThumbnailLocation"], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)757.98425, (float)25.51, (float)163.8425, (float)84.47244);
                    }
                    catch (Exception ex)
                    {
                    }

                    string offerClientTemp = (drOfferPrintoutPP_View["OfferUD"].ToString()).Substring(10);
                    string offerClientName = offerClientTemp.Substring(0, offerClientTemp.IndexOf('/'));
                    //Add Text
                    var shape = slide1.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)112.252, (float)143.4331, (float)763.37, (float)118.2047);
                    shape.TextFrame.TextRange.Text      = "Offer " + offerClientName;
                    shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorBottom;
                    shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame.TextRange.Font.Name = "Calibri";
                    shape.TextFrame.TextRange.Font.Size = 44;
                    shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.HorizontalAnchor    = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                    shape.TextFrame.TextRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignCenter;
                    shape.Width  = (float)763.37;
                    shape.Height = (float)118.2047;
                    shape.Left   = (float)112.252;
                    shape.Top    = (float)143.4331;

                    string season = drOfferPrintoutPP_View["Season"].ToString().Replace("/", "-");

                    shape = slide1.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)119.9055, (float)279.2126, (float)720, (float)77.66929);
                    shape.TextFrame.TextRange.Text      = "Season " + season;
                    shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                    shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.TextRange.Font.Name = "Calibri";
                    shape.TextFrame.TextRange.Font.Size = 24;
                    shape.TextFrame.HorizontalAnchor    = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                    shape.Width  = (float)720;
                    shape.Height = (float)77.66929;

                    // add line
                    shape = slide1.Shapes.AddLine(0, (float)432.85, (float)960.1, (float)432.85);
                    shape.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(64, 160, 64).ToArgb();
                    shape.Line.DashStyle     = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid;
                    shape.Line.Weight        = 3;

                    shape = slide1.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)3.685039, (float)443.90551, (float)183.1181, (float)94.3937);
                    shape.TextFrame.TextRange.Text = "Eurofar International B.V.\n" +
                                                     "Beelaerts van Bloklandstraat 14\n" +
                                                     "5042 PM Tilburg\nThe Netherlands\n" +
                                                     "Tel: +31 13 5446193\n" +
                                                     "www.eurofar.com";
                    shape.TextFrame.Orientation              = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor           = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
                    shape.TextFrame.WordWrap                 = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame2.AutoSize                = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.TextRange.Font.Name      = "Calibri";
                    shape.TextFrame.TextRange.Font.Size      = 12;
                    shape.TextFrame.TextRange.Font.Color.RGB = System.Drawing.Color.FromArgb(22, 132, 22).ToArgb();
                    shape.TextFrame.HorizontalAnchor         = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorNone;
                    shape.Width  = (float)183.1181;
                    shape.Height = (float)94.3937;

                    shape = slide1.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)267.874, (float)444.75591, (float)348.37795, (float)65.48031);
                    shape.TextFrame.TextRange.Text = "Eurofar contactperson:            " + drOfferPrintoutPP_View["SaleNM"] + "\n" +
                                                     "Email:                                          " + drOfferPrintoutPP_View["SaleEmail"] + "\n" +
                                                     "Phone:                                        " + drOfferPrintoutPP_View["SaleTelephone"];
                    shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                    shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.TextRange.Font.Name = "Calibri";
                    shape.TextFrame.TextRange.Font.Size = 12;
                    shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                    shape.TextFrame.HorizontalAnchor    = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorNone;
                    shape.Width  = (float)348.37795;
                    shape.Height = (float)65.48031;

                    shape = slide1.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)621.92126, (float)444.75591, (float)318.89764, (float)51.0236);
                    shape.TextFrame.TextRange.Text = "Your contactperson:                " + drOfferPrintoutPP_View["ClientContactPerson"] + "\n" +
                                                     "Email:                                         " + drOfferPrintoutPP_View["ClientContactEmail"] + "\n" +
                                                     "Phone:                                       " + drOfferPrintoutPP_View["ClientContactPhone"];
                    shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                    shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.TextRange.Font.Name = "Calibri";
                    shape.TextFrame.TextRange.Font.Size = 12;
                    shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                    shape.TextFrame.HorizontalAnchor    = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorNone;
                    shape.Width  = (float)318.89764;
                    shape.Height = (float)65.48031;

                    //Add Slide 2
                    var slide2 = presentation.Slides.AddSlide(presentation.Slides.Count + 1, presentation.SlideMaster.CustomLayouts[1]);
                    slide2.Layout = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank;

                    //Add logo
                    slide2.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "eurofar-logo.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)343.84252, (float)31.1811);

                    //Add Text 1
                    shape = slide2.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)127.8425, (float)128.6929, (float)720, (float)112.252);
                    shape.TextFrame.TextRange.Text      = "Here with we have the pleasure to send you this customized quotation.\nThe items in this offer are based on your selection and includes the latest\ntrends and developments in the market.";
                    shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                    shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.TextRange.Font.Name = "Calibri Light";
                    shape.TextFrame.TextRange.Font.Size = 24;
                    shape.TextFrame.TextRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignCenter;
                    shape.TextFrame.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                    shape.Width  = (float)720;
                    shape.Height = (float)112.252;

                    // add line
                    shape = slide2.Shapes.AddLine(0, (float)255.685, (float)960.1, (float)255.685);
                    shape.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(64, 160, 64).ToArgb();
                    shape.Line.DashStyle     = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid;
                    shape.Line.Weight        = 3;

                    string validUntil = "";
                    if (drOfferPrintoutPP_View["ValidUntil"].ToString().Trim() != "")
                    {
                        validUntil = drOfferPrintoutPP_View["ValidUntil"].ToString().Substring(0, 10);
                    }
                    //Add Text 2
                    shape = slide2.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)109.7008, (float)255.685, (float)793.701, (float)253.1339);
                    shape.TextFrame.TextRange.Text = "Our offer is based on:\n\r" +
                                                     drOfferPrintoutPP_View["DeliveryTermNM"] + "\n" +
                                                     "Prices in " + drOfferPrintoutPP_View["Currency"] + "\n" +
                                                     drOfferPrintoutPP_View["PaymentTermNM"] + "\n" +
                                                     drOfferPrintoutPP_View["Remark"] + "\n" +
                                                     "Prices valid until " + validUntil;
                    shape.TextFrame.TextRange.Lines(1).ParagraphFormat.Alignment        = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignCenter;
                    shape.TextFrame.TextRange.Paragraphs(2).ParagraphFormat.Bullet.Type = Microsoft.Office.Interop.PowerPoint.PpBulletType.ppBulletUnnumbered;
                    shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                    shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                    shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                    shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                    shape.TextFrame.TextRange.Font.Name = "Calibri Light";
                    shape.TextFrame.TextRange.Font.Size = 24;
                    shape.Width  = (float)720;
                    shape.Height = (float)253.1339;

                    foreach (DataRow dr in dtOfferPrintoutPP_Detail_View.Rows)
                    {
                        //Add Slide 3
                        var slide3 = presentation.Slides.AddSlide(presentation.Slides.Count + 1, presentation.SlideMaster.CustomLayouts[1]);
                        slide3.Layout = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank;

                        try
                        {
                            // add large picture
                            shape                 = slide3.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "file/" + dr["GardenImageLocation"].ToString(), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0);
                            shape.Width           = (float)962.07874;
                            shape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoFalse;
                            shape.Height          = (float)543.9685;
                        }
                        catch (Exception ex)
                        {
                        }


                        //Add Text 1
                        shape = slide3.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)401.95276, (float)464.8819, (float)448.15748, (float)84.47244);
                        shape.TextFrame.TextRange.Text           = dr["ModelNM"].ToString();
                        shape.TextFrame.Orientation              = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                        shape.TextFrame.VerticalAnchor           = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
                        shape.TextFrame.WordWrap                 = Microsoft.Office.Core.MsoTriState.msoTrue;
                        shape.TextFrame.TextRange.Font.Name      = "Calibri";
                        shape.TextFrame.TextRange.Font.Size      = 44;
                        shape.TextFrame2.AutoSize                = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                        shape.TextFrame.TextRange.Font.Color.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
                        shape.Width  = (float)448.15748;
                        shape.Height = (float)84.47244;
                        shape.Left   = (float)401.95276;
                        shape.Top    = (float)464.8819;

                        shape        = slide3.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "offer-print-pp-image-1.png", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)767.90551, (float)480.18898);
                        shape.Width  = (float)181.9843;
                        shape.Height = (float)49.6063;

                        //Add Slide 4
                        var slide4 = presentation.Slides.AddSlide(presentation.Slides.Count + 1, presentation.SlideMaster.CustomLayouts[1]);
                        slide4.Layout = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank;

                        string productName = dr["ModelNM"].ToString();
                        if (int.Parse(dr["ProductTypeID"].ToString()) == 5)
                        {
                            productName = productName.Substring(0, productName.IndexOf("(")) + productName.Substring(productName.LastIndexOf(")") + 1);
                        }

                        //Add Text 1
                        shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)13.6063, (float)14.45669, (float)828, (float)109.4173);
                        shape.TextFrame.TextRange.Text = productName + "\r" +
                                                         "Reference: " + dr["ModelUD"];
                        shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                        shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
                        shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                        shape.TextFrame.TextRange.Font.Name = "Calibri";
                        shape.TextFrame.TextRange.Font.Size = 44;
                        shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                        shape.TextFrame.TextRange.Paragraphs(1).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                        shape.TextFrame.TextRange.Paragraphs(2).Font.Size = 16;
                        shape.Width  = (float)448.15748;
                        shape.Height = (float)84.47244;
                        shape.Left   = (float)13.6063;
                        shape.Top    = (float)14.45669;

                        shape        = slide4.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "offer-print-pp-image-1.png", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)733.32283, (float)5.102362);
                        shape.Width  = (float)221.9528;
                        shape.Height = (float)60.37795;

                        string freescanImageLocation = dr["FreescanImageLocation"].ToString();

                        try
                        {
                            // add large picture
                            shape        = slide4.Shapes.AddPicture(FrameworkSetting.Setting.MediaUrl + "thumbnail/" + freescanImageLocation, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)23.81102, (float)112.8189);
                            shape.Width  = (float)409.03937;
                            shape.Height = (float)176.8819;
                        }
                        catch (Exception ex)
                        {
                        }

                        //Add text 2
                        string currentcy = "";
                        if (drOfferPrintoutPP_View["Currency"].ToString() == "USD")
                        {
                            currentcy = "$ ";
                        }
                        else
                        {
                            if (drOfferPrintoutPP_View["Currency"].ToString() == "EUR")
                            {
                                currentcy = "€ ";
                            }
                        }
                        shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)598.1102, (float)185.6693, (float)334.20472, (float)32.88189);
                        shape.TextFrame.TextRange.Text      = "Unit Price\t" + currentcy + float.Parse(dr["FinalPrice"].ToString()).ToString("n2");
                        shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                        shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                        shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                        shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                        shape.TextFrame.TextRange.Font.Name = "Calibri";
                        shape.TextFrame.TextRange.Font.Size = 24;
                        shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                        shape.TextFrame.HorizontalAnchor    = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorNone;
                        shape.Width  = (float)334.20472;
                        shape.Height = (float)32.88189;

                        //Add text 3
                        string tab1 = "", tab2 = "", tab3 = "", tab4 = "";
                        if (dr["MaterialNM"].ToString().Length <= 18 && dr["MaterialNM"].ToString().Length > 8)
                        {
                            tab1 = "\t";
                        }
                        else if (dr["MaterialNM"].ToString().Length <= 8)
                        {
                            tab1 = "\t\t";
                        }

                        if (dr["SubMaterialNM"].ToString().Length <= 18 && dr["SubMaterialNM"].ToString().Length > 8)
                        {
                            tab2 = "\t";
                        }
                        else if (dr["SubMaterialNM"].ToString().Length <= 8)
                        {
                            tab2 = "\t\t";
                        }

                        if (dr["FrameMaterialNM"].ToString().Length <= 18 && dr["FrameMaterialNM"].ToString().Length > 8)
                        {
                            tab3 = "\t";
                        }
                        else if (dr["FrameMaterialNM"].ToString().Length <= 8)
                        {
                            tab3 = "\t\t";
                        }

                        if ((dr["SeatCushionNM"].ToString().Length + 13) <= 18)
                        {
                            tab4 = "\t";
                        }
                        shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)23.81102, (float)295.65354, (float)908.50394, (float)105.7323);
                        shape.TextFrame.TextRange.Text = "Material 1: \t" + dr["MaterialNM"] + tab1 + "\tColor:\t" + dr["MaterialColorNM"] + "\n" +
                                                         "Material 2: \t" + dr["SubMaterialNM"] + tab2 + "\tColor:\t" + dr["SubMaterialColorNM"] + "\n" +
                                                         "Frame:\t\t" + dr["FrameMaterialNM"] + tab3 + "\tColor:\t" + dr["FrameMaterialColorNM"] + "\n" +
                                                         "Cushion:\t\tSeatcushion: " + dr["SeatCushionNM"] + tab4 + "\tColor:\t" + dr["CushionColorNM"] + "\n" +
                                                         "\t\tBackcushion: " + dr["BackCushionNM"];
                        shape.TextFrame.Orientation         = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                        shape.TextFrame.VerticalAnchor      = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                        shape.TextFrame.WordWrap            = Microsoft.Office.Core.MsoTriState.msoTrue;
                        shape.TextFrame2.AutoSize           = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                        shape.TextFrame.TextRange.Font.Name = "Calibri";
                        shape.TextFrame.TextRange.Font.Size = 16;
                        shape.Width  = (float)908.50394;
                        shape.Height = (float)105.7323;

                        // add line
                        shape = slide4.Shapes.AddLine(0, (float)406.77165, (float)960.1, (float)406.77165);
                        shape.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(64, 160, 64).ToArgb();
                        shape.Line.DashStyle     = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid;
                        shape.Line.Weight        = 3;

                        if (int.Parse(dr["ProductTypeID"].ToString()) == 5)
                        {
                            string txtDetail    = "";
                            string txtPackaging = "";
                            int    boxNumber    = 1;
                            string tab          = "";

                            foreach (DataRow drDetail in dtOfferPrintoutPP_PieceDetail_View.Rows)
                            {
                                string modelNameTemp = drDetail["ModelNM"].ToString();
                                string modelName     = modelNameTemp.Substring(modelNameTemp.IndexOf(" "));
                                if (modelName.Length > 18)
                                {
                                    modelName = modelName.Substring(0, 15) + "...";
                                }
                                if ((modelName.Substring(modelName.IndexOf(" ")).Length + 6) < 16)
                                {
                                    tab = "\t";
                                }
                                else
                                {
                                    tab = "";
                                }

                                if (drDetail["ModelID"].ToString() == dr["ModelID"].ToString() && drDetail["PackagingMethodID"].ToString() == dr["PackagingMethodID"].ToString())
                                {
                                    txtDetail    += drDetail["Quantity"] + " x" + modelName + ": " + tab + "\tL: " + drDetail["OverallDimL"] + " x W: " + drDetail["OverallDimW"] + " x H: " + drDetail["OverallDimH"] + " CM\t\tQnt/40’HC: \t" + drDetail["Qnt40HC"] + "\n";
                                    txtPackaging += "Box " + boxNumber + ":\tL: " + drDetail["CartonBoxDimL"] + " x W: " + drDetail["CartonBoxDimW"] + " x H: " + drDetail["CartonBoxDimH"] + " CM\n";
                                    boxNumber++;
                                }
                            }
                            //Add text 4
                            shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)23.81102, (float)419.81102, (float)514.20472, (float)113.6693);
                            shape.TextFrame.TextRange.Text = "Specifications and loading:\n" + txtDetail + "\r" +
                                                             "\t\t\t\t\tSets/40’HC:\t" + dr["Qnt40HC"];
                            shape.TextFrame.Orientation                       = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                            shape.TextFrame.VerticalAnchor                    = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                            shape.TextFrame.WordWrap                          = Microsoft.Office.Core.MsoTriState.msoTrue;
                            shape.TextFrame2.AutoSize                         = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                            shape.TextFrame.TextRange.Font.Name               = "Calibri";
                            shape.TextFrame.TextRange.Lines(1).Font.Bold      = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            shape.TextFrame.TextRange.Paragraphs(2).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            //shape.TextFrame.TextRange.Lines(10).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            shape.TextFrame.TextRange.Font.Size = 13;
                            shape.Width  = (float)514.20472;
                            shape.Height = (float)113.6693;

                            //Add text 5
                            shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)598.1102, (float)426.89764, (float)346.67717, (float)96.09449);
                            shape.TextFrame.TextRange.Text               = "Packaging:\tStandard with carton box\n\n" + txtPackaging;
                            shape.TextFrame.Orientation                  = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                            shape.TextFrame.VerticalAnchor               = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                            shape.TextFrame.WordWrap                     = Microsoft.Office.Core.MsoTriState.msoTrue;
                            shape.TextFrame2.AutoSize                    = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                            shape.TextFrame.TextRange.Font.Name          = "Calibri";
                            shape.TextFrame.TextRange.Font.Size          = 13;
                            shape.TextFrame.TextRange.Words(1).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            shape.Width  = (float)346.67717;
                            shape.Height = (float)96.09449;
                        }
                        else
                        {
                            //Add text 4
                            string modelName = dr["ModelNM"].ToString();
                            if (modelName.Length > 18)
                            {
                                modelName = modelName.Substring(0, 15) + "...";
                            }
                            string tab = "";
                            if (("L: " + dr["OverallDimL"] + " x W: " + dr["OverallDimW"] + " x H: " + dr["OverallDimH"] + " CM").Length < 26)
                            {
                                tab = "\t";
                            }
                            shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)23.81102, (float)419.81102, (float)514.20472, (float)113.6693);
                            shape.TextFrame.TextRange.Text = "Specifications and loading:\n" +
                                                             "1 x " + modelName + ":\t L: " + dr["OverallDimL"] + " x W: " + dr["OverallDimW"] + " x H: " + dr["OverallDimH"] + " CM" + tab + "\tQnt/40’HC: 	"+ dr["Qnt40HC"];
                            shape.TextFrame.Orientation                  = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                            shape.TextFrame.VerticalAnchor               = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                            shape.TextFrame.WordWrap                     = Microsoft.Office.Core.MsoTriState.msoTrue;
                            shape.TextFrame2.AutoSize                    = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                            shape.TextFrame.TextRange.Font.Name          = "Calibri";
                            shape.TextFrame.TextRange.Font.Size          = 13;
                            shape.TextFrame.TextRange.Lines(1).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            shape.TextFrame.TextRange.Lines(7).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            shape.Width  = (float)514.20472;
                            shape.Height = (float)113.6693;

                            //Add text 5
                            shape = slide4.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, (float)598.1102, (float)426.89764, (float)346.67717, (float)96.09449);
                            shape.TextFrame.TextRange.Text = "Packaging:\tStandard with carton box\n\n" +
                                                             "Box 1:\tL: " + dr["CartonBoxDimL"] + " x W: " + dr["CartonBoxDimW"] + " x H: " + dr["CartonBoxDimH"] + " CM";
                            shape.TextFrame.Orientation                  = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal;
                            shape.TextFrame.VerticalAnchor               = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
                            shape.TextFrame.WordWrap                     = Microsoft.Office.Core.MsoTriState.msoTrue;
                            shape.TextFrame2.AutoSize                    = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
                            shape.TextFrame.TextRange.Font.Name          = "Calibri";
                            shape.TextFrame.TextRange.Font.Size          = 13;
                            shape.TextFrame.TextRange.Words(1).Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;
                            shape.Width  = (float)346.67717;
                            shape.Height = (float)96.09449;
                        }
                    }

                    // save file and close powerpoint
                    string filename = System.Guid.NewGuid().ToString().Replace("-", "") + ".pptx";
                    string fullpath = FrameworkSetting.Setting.AbsoluteReportTmpFolder + filename;
                    presentation.SaveAs(fullpath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                    presentation.Close();
                    app.Quit();
                    return(filename);
                }
                catch
                {
                }
            }

            return(string.Empty);
        }
Exemple #29
0
    /// <summary>
    /// スライドを読み込む
    /// </summary>
    /// <param name="action">読み込みが完了した際のアクション</param>
    public void Init(Action <SlideDataRaw[]> action)
    {
        if (string.IsNullOrEmpty(slidePath) || string.IsNullOrEmpty(temporaryFilePath))
        {
            Debug.LogError("[SlideLoader] Invalid file path.");
            return;
        }
        if (!File.Exists(slidePath) || !Directory.Exists(temporaryFilePath))
        {
            Debug.LogError("[SlideLoader] File not found.");
            return;
        }
        var extension = Path.GetExtension(slidePath);

        if (!(extension == ".pptx" || extension == ".ppt"))
        {
            Debug.LogError("[SlideLoader] File format must be \".ppt\" or \".pptx\"");
            return;
        }

        Debug.Log("[SlideLoader] Load Slide.");
        slides = null;
        Microsoft.Office.Interop.PowerPoint.Application  app = null;
        Microsoft.Office.Interop.PowerPoint.Presentation ppt = null;

        Task.Run(() =>
        {
            try
            {
                app = new Microsoft.Office.Interop.PowerPoint.Application();

                // スライドを開く
                ppt = app.Presentations.Open(slidePath, MsoTriState.msoTrue, MsoTriState.msoFalse,
                                             MsoTriState.msoFalse);

                var width  = (int)ppt.PageSetup.SlideWidth;
                var height = (int)ppt.PageSetup.SlideHeight;

                var slideList = new List <SlideDataRaw>();

                for (var i = 1; i <= ppt.Slides.Count; i++)
                {
                    // 非表示スライドは無視
                    if (ppt.Slides[i].SlideShowTransition.Hidden == MsoTriState.msoTrue)
                    {
                        continue;
                    }

                    // コメント
                    var note = ppt.Slides[i].NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text;
                    if (note == "")
                    {
                        continue;
                    }

                    // JPEGとして保存
                    var file = temporaryFilePath + $"/slide{i:0000}.jpg";
                    ppt.Slides[i].Export(file, "jpg", width, height);

                    slideList.Add(new SlideDataRaw()
                    {
                        note = note, imageFilePath = file
                    });
                }

                slides = slideList.ToArray();
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
            finally
            {
                ppt?.Close();
                app?.Quit();
            }
        }).ContinueWith(_ =>
        {
            Debug.Log("[SlideLoader] Load completed.");
            action.Invoke(slides);
        });
    }
        /// <summary>
        /// 把PowerPoint文件转换成PDF格式文件
        /// </summary>
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PowerPointToPDF(string sourcePath, string targetPath)
        {
            targetPath = Regex.Replace(targetPath, " ", "", RegexOptions.IgnoreCase);//去除字符串中间的空格
            bool result;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation     persentation = null;
            try
            {
                bool TimeOver             = false; //转换时间到了
                System.Timers.Timer timer = new System.Timers.Timer(30000);
                timer.AutoReset = false;           //只循环一次
                timer.Elapsed  += delegate(object sender, System.Timers.ElapsedEventArgs e)
                {
                    TimeOver = true;
                };
                timer.Start();
                Thread th = new Thread(new ThreadStart(delegate()
                {
                    try
                    {
                        application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                        //application.Visible = MsoTriState.msoFalse;
                        persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                        persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
                    }
                    catch
                    {
                    }
                }));
                th.IsBackground = true;//后台线程
                th.Start();
                //如果转换没有成功就一直循环
                while (th.ThreadState != System.Threading.ThreadState.Stopped)
                {
                    //如果一直没有转换成功,但是最大的转换时间到了也直接跳出While循环
                    if (TimeOver)
                    {
                        break;
                    }
                }
                if (th.ThreadState != System.Threading.ThreadState.Stopped)
                {
                    th.Abort();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                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();
            }
            //判断文件是否转换成功
            if (File.Exists(targetPath))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }