예제 #1
0
        protected Stream GetPreviewImagesPowerPointStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Slides);

            try
            {
                var ms              = new MemoryStream();
                var extension       = ContentNamingHelper.GetFileExtension(content.Name).ToLower();
                var oldPpt          = PRESENTATION_EXTENSIONS.Contains(extension);
                var saveFormat      = oldPpt ? Aspose.Slides.Export.SaveFormat.Ppt : Aspose.Slides.Export.SaveFormat.Pptx;
                var docPresentation = new Presentation();
                var index           = 1;

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, restrictionType: restrictionType))
                    {
                        var image            = System.Drawing.Image.FromStream(imgStream);
                        var imageForDocument = ResizeImage(image, Math.Min(image.Width, PREVIEW_POWERPOINT_WIDTH), Math.Min(image.Height, 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(Aspose.Slides.ShapeType.Rectangle, 10, 10,
                                                             imageForDocument.Width, imageForDocument.Height,
                                                             img);
                            }
                            catch (IndexOutOfRangeException ex)
                            {
                                Logger.WriteException(new Exception("Error during document generation. Path: " + previewImage.Path, ex));
                                break;
                            }
                        }
                    }

                    index++;
                }

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

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

            return(null);
        }
예제 #2
0
        protected static DocumentFormat GetFormatByName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(DocumentFormat.Pdf);
            }

            var extension = ContentNamingHelper.GetFileExtension(fileName).ToLower();

            if (PDF_EXTENSIONS.Contains(extension))
            {
                return(DocumentFormat.Pdf);
            }

            if (PRESENTATION_EXTENSIONS.Contains(extension))
            {
                return(DocumentFormat.Ppt);
            }

            if (PRESENTATIONEX_EXTENSIONS.Contains(extension))
            {
                return(DocumentFormat.Pptx);
            }

            if (WORKBOOK_EXTENSIONS.Contains(extension))
            {
                return(extension.EndsWith("x") ? DocumentFormat.Xlsx : DocumentFormat.Xls);
            }

            if (WORD_EXTENSIONS.Contains(extension))
            {
                return(extension.EndsWith("x") ? DocumentFormat.Docx : DocumentFormat.Doc);
            }

            return(DocumentFormat.Pdf);
        }
예제 #3
0
 public override bool IsContentSupported(STORAGE.Node content)
 {
     return(SUPPORTED_EXTENSIONS.Contains(ContentNamingHelper.GetFileExtension(content.Name).ToLower()));
 }