Пример #1
0
        /// <summary>
        /// PowerPoint格式转换(PowerPoint文件不能为空,默认转成PDF)
        /// </summary>
        /// <param name="sourcePath">源路径</param>
        /// <param name="targetPath">目标路径</param>
        /// <param name="targetFileType">转换类型</param>
        /// <returns></returns>
        public static bool PowerPointConvert(string sourcePath, string targetPath, Aspose.Slides.Export.SaveFormat targetFileType = Aspose.Slides.Export.SaveFormat.Pdf)
        {
            var extension = new FileInfo(sourcePath).Extension.ToLower();

            if (extension == ".ppt")
            {
                var ppt = new Aspose.Slides.Presentation(@sourcePath);
                ppt.Save(@targetPath, targetFileType);
                return(true);
            }

            if (extension == ".pptx")
            {
                var pptx = new Aspose.Slides.Pptx.PresentationEx(@sourcePath);
                pptx.Save(@targetPath, targetFileType);
                return(true);
            }

            throw new IOException(sourcePath + "  非PowerPoint文件");
        }
Пример #2
0
        public byte[] GetProcessedTemplate(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.SchedaDocumento sd)
        {
            byte[] content = null;
            System.IO.MemoryStream stream = new System.IO.MemoryStream();

            // Percorso modello
            string pathModel = sd.template.PATH_MODELLO_1;

            try
            {
                //System.IO.FileStream licenseStream = new System.IO.FileStream("C:\\Temp\\Aspose.total.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read);

                // Caricamento licenza
                DocsPaDB.Query_DocsPAWS.ClientSideModelProcessor csmp = new DocsPaDB.Query_DocsPAWS.ClientSideModelProcessor();

                Aspose.Slides.License lic = new License();
                byte[] licenseContent     = csmp.GetLicense("ASPOSE");
                if (licenseContent != null)
                {
                    System.IO.MemoryStream licenseStream = new System.IO.MemoryStream(licenseContent, 0, licenseContent.Length);
                    lic.SetLicense(licenseStream);
                    licenseStream.Close();
                }

                DocsPaVO.Modelli.ModelKeyValuePair[] commonFields = this.GetModelKeyValuePairs(infoUtente, sd);

                // Lettura modello con Aspose
                using (Presentation ppt = new Presentation(pathModel))
                {
                    // 1 - Analisi master
                    foreach (LayoutSlide layoutSlide in ppt.LayoutSlides)
                    {
                        foreach (IShape shape in layoutSlide.Shapes)
                        {
                            if (shape is Aspose.Slides.AutoShape)
                            {
                                if (((IAutoShape)shape).TextFrame != null)
                                {
                                    string text = ((IAutoShape)shape).TextFrame.Text;
                                    if (!string.IsNullOrEmpty(text))
                                    {
                                        this.SearchAndReplaceFields(ref text, commonFields);
                                        ((IAutoShape)shape).TextFrame.Text = text;
                                    }
                                }
                            }
                        }
                    }

                    // Lettura caselle di testo
                    ITextFrame[] textFrames = Aspose.Slides.Util.SlideUtil.GetAllTextFrames(ppt, true);

                    foreach (ITextFrame tf in textFrames)
                    {
                        foreach (Paragraph par in tf.Paragraphs)
                        {
                            string text = par.Text;
                            if (!string.IsNullOrEmpty(text) && text.Contains("#"))
                            {
                                this.SearchAndReplaceFields(ref text, commonFields);
                                par.Text = text;
                            }
                            #region OLD CODE
                            //foreach (Portion port in par.Portions)
                            //{
                            //    string text = port.Text;
                            //    if (!string.IsNullOrEmpty(text) && text.Contains("#"))
                            //    {
                            //        this.SearchAndReplaceFields(ref text, commonFields);
                            //        port.Text = text;
                            //    }
                            //}
                            #endregion
                        }
                    }

                    #region OLD CODE
                    //Lettura slide
                    //foreach (ISlide slide in ppt.Slides)
                    //{
                    //    // Ciclo sulle forme della slide
                    //    foreach (IShape shape in slide.Shapes)
                    //    {
                    //        // Analisi testo
                    //        if (((IAutoShape)shape).TextFrame != null)
                    //        {
                    //            string text = ((IAutoShape)shape).TextFrame.Text;
                    //            if (!string.IsNullOrEmpty(text))
                    //            {
                    //                this.SearchAndReplaceFields(ref text, commonFields);
                    //                ((IAutoShape)shape).TextFrame.Text = text;
                    //            }
                    //        }
                    //    }
                    //}
                    #endregion

                    // Salvataggio del documento
                    Aspose.Slides.Export.SaveFormat frm = new Aspose.Slides.Export.SaveFormat();
                    switch (sd.template.PATH_MODELLO_1_EXT.ToUpper())
                    {
                    case "PPT":
                    default:
                        frm = Aspose.Slides.Export.SaveFormat.Ppt;
                        break;

                    case "PPTX":
                        frm = Aspose.Slides.Export.SaveFormat.Pptx;
                        break;

                    case "PPSX":
                        frm = Aspose.Slides.Export.SaveFormat.Ppsx;
                        break;

                    case "ODP":
                        frm = Aspose.Slides.Export.SaveFormat.Odp;
                        break;
                    }

                    ppt.Save(stream, Aspose.Slides.Export.SaveFormat.Pptx);
                }

                content = stream.ToArray();
            }
            catch (Exception ex)
            {
                logger.DebugFormat("{0}\r\n{1}", ex.Message, ex.StackTrace);
                content = null;
            }
            return(content);
        }