Esempio n. 1
0
        private static void GenerateVideoFromAspose(string sourcePath, string extension)
        {
            var pptPresentation     = new Aspose.Slides.Presentation();
            ISlideCollection slides = pptPresentation.Slides;

            var dirInfo     = new DirectoryInfo(sourcePath);
            var jpgFileList = new List <string>();

            if (dirInfo.Exists)
            {
                jpgFileList.AddRange(dirInfo.GetFiles().Where(f => f.Extension.Equals(extension)).OrderBy(f => f.LastWriteTime).Take(3).Select(fileToUpload => sourcePath + "\\" + fileToUpload.Name));
            }

            //Aspose.Slides.Slide slide;
            for (int i = 0; i < jpgFileList.Count; i++)
            {
                var slide = slides.AddEmptySlide(pptPresentation.LayoutSlides[i + 1]);
                //Set the background with Image
                slide.Background.Type = BackgroundType.OwnBackground;
                slide.Background.FillFormat.FillType = FillType.Picture;
                slide.Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;

                //Set the picture
                var img = (System.Drawing.Image) new Bitmap(jpgFileList[i]);

                //Add image to presentation's images collection
                IPPImage imgx = pptPresentation.Images.AddImage(img);

                slide.Background.FillFormat.PictureFillFormat.Picture.Image = imgx;
            }

            //Save the PPTX file to the Disk
            pptPresentation.Save(sourcePath + "\\EmptySlide.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
        }
Esempio n. 2
0
 /// <summary>
 /// 将PowerPoint文件转换为PDF
 /// </summary>
 /// <param name="sourceFileName">PPT/PPTX文件路径</param>
 /// <param name="targetFileName">目标文件路径</param>
 /// <returns>转换是否成功</returns>
 public static bool ConvertPowerPointToPdf(string sourceFileName, string targetFileName)
 {
     // Souxuexiao.API.Logger.info(string.Format("准备执行PowerPoint转换PDF,sourceFileName={0},targetFileName={1}", sourceFileName, targetFileName));
     try
     {
         using (System.IO.Stream stream = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
         {
             Aspose.Slides.Presentation pptx = new Aspose.Slides.Presentation(sourceFileName);
             pptx.Save(targetFileName, Aspose.Slides.Export.SaveFormat.Pdf);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(System.IO.File.Exists(targetFileName));
 }
Esempio n. 3
0
        private static void PowerPointSlideToImage()
        {
            using (Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation(@"C:\test.pptx"))
            {
                for (int i = 0; i < pres.Slides.Count; i++)
                {
                    var sld      = pres.Slides[i];
                    int desiredX = 1200;
                    int desiredY = 800;

                    float ScaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX;
                    float ScaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY;

                    var bmp = sld.GetThumbnail(ScaleX, ScaleY);

                    bmp.Save(@"C:\pptSlide" + i + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                }
            }
        }
Esempio n. 4
0
        protected Stream GetPreviewImagesPowerPointStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Slides);

            try
            {
                var ms              = new MemoryStream();
                var extension       = ContentNamingProvider.GetFileExtension(content.Name).ToLower();
                var oldPpt          = Common.PRESENTATION_EXTENSIONS.Contains(extension);
                var saveFormat      = oldPpt ? AsposeSlides.Export.SaveFormat.Ppt : AsposeSlides.Export.SaveFormat.Pptx;
                var docPresentation = new AsposeSlides.Presentation();
                var index           = 1;
                var imageOptions    = new PreviewImageOptions()
                {
                    RestrictionType = restrictionType
                };

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, imageOptions))
                    {
                        var image            = System.Drawing.Image.FromStream(imgStream);
                        var imageForDocument = ResizeImage(image, Math.Min(image.Width, Common.PREVIEW_POWERPOINT_WIDTH), Math.Min(image.Height, Common.PREVIEW_POWERPOINT_HEIGHT));

                        if (imageForDocument != null)
                        {
                            try
                            {
                                var img   = docPresentation.Images.AddImage(imageForDocument);
                                var slide = docPresentation.Slides[0];
                                if (index > 1)
                                {
                                    docPresentation.Slides.AddClone(slide);
                                    slide = docPresentation.Slides[index - 1];
                                }

                                slide.Shapes.AddPictureFrame(AsposeSlides.ShapeType.Rectangle, 10, 10,
                                                             imageForDocument.Width, imageForDocument.Height,
                                                             img);
                            }
                            catch (IndexOutOfRangeException ex)
                            {
                                SnLog.WriteException(ex, "Error during document generation. Path: " + previewImage.Path);
                                break;
                            }
                        }
                    }

                    index++;
                }

                docPresentation.Save(ms, saveFormat);
                ms.Seek(0, SeekOrigin.Begin);

                return(ms);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }

            return(null);
        }
Esempio n. 5
0
        public static void ConvertToPdf(string inputFilePath, string outputFilePath)
        {
            var extension = Path.GetExtension(inputFilePath);
            if (extension == null)
            {
                return;
            }

            switch (extension.ToUpperInvariant())
            {
                case ".DOC":
                case ".DOCX":
                case ".RTF":
                case ".DOT":
                case ".DOTX":
                    var doc = new Document(inputFilePath);
                    doc.Save(outputFilePath, Aspose.Words.SaveFormat.Pdf);
                    break;
                case ".XLS":
                case ".XLSX":
                    var workbook = new Workbook(inputFilePath);
                    workbook.Save(outputFilePath, Aspose.Cells.SaveFormat.Pdf);
                    break;
                //Microsoft Visio 
                case ".VSD":
                case ".VSS":
                case ".VST":
                case ".VSX":
                case ".VTX":
                case ".VDW":
                case ".VDX":
                    var diagram = new Diagram(inputFilePath);
                    diagram.Save(outputFilePath, SaveFileFormat.PDF);
                    break;
                //Microsoft Project
                case ".MPP":
                    var project = new Aspose.Tasks.Project(inputFilePath);
                    project.Save(outputFilePath, Aspose.Tasks.Saving.SaveFileFormat.PDF);
                    break;
                //PowerPoint
                case ".PPT":
                case ".PPS":
                case ".POT":
                    using (var pres = new Aspose.Slides.Presentation(inputFilePath))
                        pres.Save(outputFilePath, Aspose.Slides.Export.SaveFormat.Pdf);
                    break;
                case ".PPTX":
                case ".PPSX":
                case ".POTX":
                    //case ".XPS":
                    using (var presEx = new Aspose.Slides.Presentation(inputFilePath))
                        presEx.Save(outputFilePath, Aspose.Slides.Export.SaveFormat.Pdf);
                    break;

                case ".PDF":
                    File.Copy(inputFilePath, outputFilePath);
                    break;
            }
        }
Esempio n. 6
0
        private static bool SavePdfToStream(string inputFile, MemoryStream fileStream, MemoryStream documentStream, ref bool isLandscape)
        {
            var extension = Path.GetExtension(inputFile);
            if (string.IsNullOrEmpty(extension))
                throw new ArgumentException(inputFile);

            try
            {
                fileStream.Position = 0;
                switch (extension.ToUpperInvariant())
                {
                    case ".DOC":
                    case ".DOCX":
                    case ".RTF":
                    case ".DOT":
                    case ".DOTX":
                        var doc = new Aspose.Words.Document(fileStream);
                        if (doc.PageCount > 0)
                        {
                            var pageInfo = doc.GetPageInfo(0);
                            isLandscape = pageInfo.WidthInPoints > pageInfo.HeightInPoints;
                        }
                        doc.Save(documentStream, Aspose.Words.SaveFormat.Pdf);
                        break;
                    case ".XLS":
                    case ".XLSX":
                        var workbook = new Aspose.Cells.Workbook(fileStream);
                        for (var i = 0; i < workbook.Worksheets.Count; i++)
                        {
                            if (!workbook.Worksheets[i].IsVisible) continue;
                            isLandscape = workbook.Worksheets[i].PageSetup.Orientation == Aspose.Cells.PageOrientationType.Landscape;
                            break;
                        }
                        workbook.Save(documentStream, Aspose.Cells.SaveFormat.Pdf);
                        break;
                    //Microsoft Visio 
                    case ".VSD":
                    case ".VSS":
                    case ".VST":
                    case ".VSX":
                    case ".VTX":
                    case ".VDW":
                    case ".VDX":
                        var vsdDiagram = new Aspose.Diagram.Diagram(fileStream);
                        if (vsdDiagram.Pages.Count > 0)
                            isLandscape = vsdDiagram.Pages[0].PageSheet.PrintProps.PrintPageOrientation.Value == Aspose.Diagram.PrintPageOrientationValue.Landscape;
                        vsdDiagram.Save(documentStream, Aspose.Diagram.SaveFileFormat.PDF);
                        break;
                    //Microsoft Project
                    case ".MPP":
                        var project = new Aspose.Tasks.Project(fileStream);
                        project.Save(documentStream, Aspose.Tasks.Saving.SaveFileFormat.PDF);
                        isLandscape = true;
                        break;
                    //PowerPoint
                    case ".PPT":
                    case ".PPS":
                    case ".POT":
                        using (var pres = new Aspose.Slides.Presentation(fileStream))
                        {
                            isLandscape = pres.SlideSize.Size.Width > pres.SlideSize.Size.Height;
                            pres.Save(documentStream, Aspose.Slides.Export.SaveFormat.Pdf);
                        }
                        break;
                    case ".PPTX":
                    case ".PPSX":
                    case ".POTX":
                        //case ".XPS":
                        using (var presEx = new Aspose.Slides.Presentation(fileStream))
                        {
                            isLandscape = presEx.SlideSize.Orientation == Aspose.Slides.SlideOrienation.Landscape;
                            presEx.Save(documentStream, Aspose.Slides.Export.SaveFormat.Pdf);
                        }
                        break;

                    case ".PDF":
                        {
                            using (var pdf = new Aspose.Pdf.Document(fileStream))
                            {
                                var page = pdf.Pages.OfType<Aspose.Pdf.Page>().FirstOrDefault();
                                if (page != null && page.MediaBox != null)
                                {
                                    isLandscape = page.MediaBox.Width > page.MediaBox.Height;
                                }
                            }

                            fileStream.Seek(0, SeekOrigin.Begin);
                            fileStream.CopyTo(documentStream);
                        }

                        break;
                }
            }
            finally
            {
                fileStream.Close();
            }

            return true;
        }
Esempio n. 7
0
            public PropertiesResponse(string path)
            {
                Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(path);
                IDocumentProperties        properties   = presentation.DocumentProperties;

                BuiltIn = new List <DocProperty>();
                Custom  = new List <DocProperty>();

                BuiltIn.Add(new DocProperty()
                {
                    Name = "ApplicationTemplate", Value = properties.ApplicationTemplate, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "AppVersion", Value = properties.AppVersion, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "Author", Value = properties.Author, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "Category", Value = properties.Category, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "Comments", Value = properties.Comments, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "Company", Value = properties.Company, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "ContentStatus", Value = properties.ContentStatus, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "ContentType", Value = properties.ContentType, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "HyperlinkBase", Value = properties.HyperlinkBase, Type = PropertyType.String
                });

                BuiltIn.Add(new DocProperty()
                {
                    Name = "Keywords", Value = properties.Keywords, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "LastSavedBy", Value = properties.LastSavedBy, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "Manager", Value = properties.Manager, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "NameOfApplication", Value = properties.NameOfApplication, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "PresentationFormat", Value = properties.PresentationFormat, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "Subject", Value = properties.Subject, Type = PropertyType.String
                });

                BuiltIn.Add(new DocProperty()
                {
                    Name = "Title", Value = properties.Title, Type = PropertyType.String
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "CreatedTime", Value = properties.CreatedTime, Type = PropertyType.DateTime
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "LastPrinted", Value = properties.LastPrinted, Type = PropertyType.DateTime
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "LastSavedTime", Value = properties.LastSavedTime, Type = PropertyType.DateTime
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "RevisionNumber", Value = properties.RevisionNumber, Type = PropertyType.Number
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "SharedDoc", Value = properties.SharedDoc, Type = PropertyType.Boolean
                });
                BuiltIn.Add(new DocProperty()
                {
                    Name = "TotalEditingTime", Value = properties.TotalEditingTime, Type = PropertyType.Time
                });

                for (int i = 0; i < properties.CountOfCustomProperties; ++i)
                {
                    string name           = properties.GetCustomPropertyName(i);
                    string _propertyValue = "";
                    properties.GetCustomPropertyValue(name, out _propertyValue);
                    Custom.Add(new DocProperty()
                    {
                        Name = name, Value = _propertyValue, Type = PropertyType.String
                    });
                }
            }
        private void generatePPT(Stream fileStream, string fileNAme)
        {
            // The path to the documents directory.
            //  string dataDir = Path.GetFullPath("ss.test.pptx");

            try
            {
                //Instantiate a Presentation object that represents a presentation file
                using (Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation(fileStream))
                {
                    HtmlOptions htmlOpt = new HtmlOptions();
                    htmlOpt.HtmlFormatter = HtmlFormatter.CreateDocumentFormatter("custom.css", false);

                    var path = @"C:\\CourseWork\\" + fileNAme + ".html";
                    //Saving the presentation to HTML
                    pres.Save(path, Aspose.Slides.Export.SaveFormat.Html, htmlOpt);

                    using (StreamReader sr = new StreamReader(path))
                    {
                        //String line = sr.ReadToEnd();//await sr.ReadToEndAsync();
                        //var txt = line;
                    }

                    var html = new HtmlDocument();
                    html.Load(path);

                    var document = html.DocumentNode;
                    var SVGs     = document.Descendants("svg");

                    Data.Presentation newPrez = new Data.Presentation();
                    newPrez.Created = DateTime.UtcNow;
                    var usr = User.Identity.Name;
                    newPrez.Name  = fileNAme;
                    newPrez.Owner = (int)WebSecurity.GetUserId(User.Identity.Name);
                    //UserProfile usr = int mu1 =
                    //newPrez.Pages = new Data.Slide();

                    List <Data.Slide> slides = new List <Data.Slide>();

                    int      counter = 0;
                    HtmlNode bckgrnd = HtmlNode.CreateNode("");
                    foreach (var item in SVGs)
                    {
                        item.Attributes.Remove("width");
                        item.Attributes.Remove("height");
                        var lastNode = item.LastChild;
                        //var decendatds = item.Descendants();
                        //var ggg = item.ChildNodes["g"];
                        //var ttt = ggg.ChildNodes.Where(x => x.Name == "text");

                        var nodesToDel = item.ChildNodes["g"].ChildNodes.Where(x => x.Name == "text").ToList();

                        foreach (var node in nodesToDel)
                        {
                            item.ChildNodes["g"].RemoveChild(node);
                        }

                        if (counter == 0)
                        {
                            bckgrnd = item.ChildNodes["defs"];
                        }
                        else
                        if (bckgrnd != null)
                        {
                            item.ChildNodes.Insert(1, bckgrnd);
                        }
                        //item.ChildNodes.Insert(0,


                        slides.Add(new Data.Slide {
                            Presentation = newPrez, SlideNo = counter, Text = item.OuterHtml
                        });

                        //string fileName = "right" + counter +".txt";
                        //FileStream fs = null;
                        //try
                        //{
                        //    fs = new FileStream(@"C:\\CourseWork\\"+fileName, FileMode.CreateNew);
                        //    using (StreamWriter writer = new StreamWriter(fs))
                        //    {
                        //        writer.Write(item.OuterHtml);
                        //    }
                        //}
                        //finally
                        //{
                        //    if (fs != null)
                        //        fs.Dispose();
                        //}
                        newPrez.Pages = slides.ToList();


                        counter++;
                    }

                    //var dbprez = newPrez;
                    //using (var ent = new Repository<Data.Presentation>())
                    //{
                    //    ent.CreatePresentation(newPrez);
                    //}
                    using (var ent = new Entities <Data.Presentation>())
                    {
                        //  ent.Add(newPrez);
                        ent.CreatePresentation(newPrez);
                    }
                }
            }
            catch (Exception ex)
            {
                PptEx = new MvcApplication6.Filters.PptException(thread, ex.Message);
            }
            finally
            {
                thread.Abort();
            }
        }