Exemple #1
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;
        }
        public static void saveSlides(Microsoft.Office.Interop.PowerPoint.Presentation presentation)
        {
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            //string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string filePath = desktopPath + "\\Slides.pptx";


            // Microsoft.Office.Interop.PowerPoint.FileConverter fc = new Microsoft.Office.Interop.PowerPoint.FileConverter();
            // if (fc.CanSave) { }
            //https://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog(v=vs.110).aspx

            //Browse Files
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.InitialDirectory = desktopPath + "\\Scano";
            dlg.DefaultExt       = ".pptx";
            dlg.Filter           = "PPTX Files (*.pptx)|*.pptx";
            Nullable <bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                filePath = dlg.FileName;
                //textBox1.Text = filename;
            }
            else
            {
                System.Console.WriteLine("Couldn't show the dialog.");
            }

            presentation.SaveAs(filePath,
                                Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
                                Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
            System.Console.WriteLine("PowerPoint application saved in {0}.", filePath);
        }
        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();
            }
        }
        /// <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());
        }
Exemple #5
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);
            }
        }
Exemple #6
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);
            }
        }
 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 #9
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 #10
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);
        }
        ///<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 #12
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 #13
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 #14
0
            public static void savePowerPoint()
            {
                try
                {
                    //saving powerpoint
                    objPres.SaveAs(path + fileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault);

                    ppApp.Quit();

                    //release memory
                    releaseObject(objTextRng);
                    releaseObject(objSlide);
                    releaseObject(objSlides);
                    releaseObject(objPres);
                    releaseObject(ppPresens);
                    releaseObject(ppApp);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error saving " + fileName);
                }
            }
        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 #16
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 #17
0
 private static void SaveSlideImage(Microsoft.Office.Interop.PowerPoint.Presentation presen)
 {
     presen.SaveAs(presen.FullName + "_img",
                   Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPNG,
                   MsoTriState.msoTrue);
 }
 public void Save(string path)
 {
     presentation.SaveAs(path, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse);
 }
 public static void SavePresentation(ref Microsoft.Office.Interop.PowerPoint.Presentation presentation, string filename)
 {
     presentation.SaveAs(filename);
 }
Exemple #20
0
            public void OutputToPPT()
            {
                Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Slides      oSlides;
                Microsoft.Office.Interop.PowerPoint._Slide      oSlide;
                Microsoft.Office.Interop.PowerPoint.TextRange   objText;

                // Create the Presentation File
                Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
                Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout    = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

                // Create new Slide
                oSlides = pptPresentation.Slides;
                oSlide  = oSlides.AddSlide(1, customLayout);

                // Add title
                objText           = oSlide.Shapes[1].TextFrame.TextRange;
                objText.Text      = "Radiation Shield";
                objText.Font.Name = "Arial";
                objText.Font.Size = 32;

                objText      = oSlide.Shapes[2].TextFrame.TextRange;
                objText.Text = "ICA report\nArtem L. Ponomarev,. Ph.D.\nOn the Fig. is the proposed \ncompound shield\nRed -- Hafnium\nGreen -- Aluminum\nGrey -- plastic\n\nPlay video to visualize passage of space particles through Hafnium";

                string appPath         = Application.StartupPath;
                string pictureFileName = appPath + "\\temp\\compoundshield2.jpg";

                Microsoft.Office.Interop.PowerPoint.Shape oShape = oSlide.Shapes[2];
                oSlide.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue,
                                         oShape.Left + 394, oShape.Top - 140, oShape.Width / 2, oShape.Height);
                oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Artem L. Ponomarev, Ph.D.";
                string movieFileName = appPath + "\\temp\\MovingParticles.avi";

                oSlide.Shapes.AddMediaObject2(movieFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue,
                                              oShape.Left + 450, oShape.Top + 120, oShape.Width / 2, oShape.Height / 2);
                ////While iterating through all slides i:
                //objShapes = objPres.Slides[i].Shapes;
                //foreach (Microsoft.Office.Interop.PowerPoint.Shape s in objShapes)
                //{
                //    if (s.Name.Contains(".wmv"))
                //    {
                //        s.AnimationSettings.PlaySettings.PlayOnEntry = MsoTriState.msoTrue;
                //    }
                //}

                // Create new Slide
                oSlides = pptPresentation.Slides;
                oSlide  = oSlides.AddSlide(1, customLayout);

                // Add title
                objText           = oSlide.Shapes[1].TextFrame.TextRange;
                objText.Text      = "Radiation Shield";
                objText.Font.Name = "Arial";
                objText.Font.Size = 32;

                // insert shape
                Microsoft.Office.Interop.PowerPoint.Shape shieldShape1 = oSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeCube, oShape.Left + 100, oShape.Top, oShape.Width / 10, oShape.Height);
                shieldShape1.Fill.ForeColor.RGB       = System.Drawing.Color.Blue.ToArgb();
                shieldShape1.TextFrame.TextRange.Text = "Hafnium";
                Microsoft.Office.Interop.PowerPoint.Shape shieldShape2 = oSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeCube, oShape.Left + 300, oShape.Top, oShape.Width / 10, oShape.Height);
                shieldShape2.Fill.ForeColor.RGB       = System.Drawing.Color.Green.ToArgb();
                shieldShape2.TextFrame.TextRange.Text = "Aluminum";
                Microsoft.Office.Interop.PowerPoint.Shape shieldShape3 = oSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeCube, oShape.Left + 200, oShape.Top, oShape.Width / 10, oShape.Height);
                shieldShape3.Fill.ForeColor.RGB       = System.Drawing.Color.Purple.ToArgb();
                shieldShape3.TextFrame.TextRange.Text = "Zirconium";
                //
                // Create new Slide
                oSlides = pptPresentation.Slides;
                oSlide  = oSlides.AddSlide(1, customLayout);

                // Add title
                objText           = oSlide.Shapes[1].TextFrame.TextRange;
                objText.Text      = "Radiation Shield";
                objText.Font.Name = "Arial";
                objText.Font.Size = 32;
                //
                Microsoft.Office.Interop.PowerPoint.Shape oShape1;
                int iRow;
                int iColumn;

                int[,] tdata = new int[, ] {
                    { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }
                };

                int iRows    = tdata.GetLength(0);
                int iColumns = tdata.GetLength(1);

                oShape1 = oSlide.Shapes.AddTable(iRows, iColumns, 500, 110, 160, 120);

                for (iRow = 1; iRow <= oShape1.Table.Rows.Count; iRow++)
                {
                    for (iColumn = 1; iColumn <= oShape1.Table.Columns.Count; iColumn++)
                    {
                        oShape1.Table.Cell(iRow, iColumn).Shape.TextFrame.TextRange.Text      = tdata.GetValue(iRow - 1, iColumn - 1).ToString();
                        oShape1.Table.Cell(iRow, iColumn).Shape.TextFrame.TextRange.Font.Name = "Verdana";
                        oShape1.Table.Cell(iRow, iColumn).Shape.TextFrame.TextRange.Font.Size = 8;
                    }
                }
                //
                // Create new Slide
                oSlides = pptPresentation.Slides;
                oSlide  = oSlides.AddSlide(1, customLayout);

                // Add title
                objText           = oSlide.Shapes[1].TextFrame.TextRange;
                objText.Text      = "Radiation Shield";
                objText.Font.Name = "Arial";
                objText.Font.Size = 32;
                //
                pptPresentation.SaveAs(appPath + "\\temp\\RadShield.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                //
                //pptPresentation.Close();
                //pptApplication.Quit();
            }
        /// <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);
            }
        }
        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 #23
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);
        }