Exemple #1
0
        protected static DocumentFormat GetFormatByName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(DocumentFormat.Pdf);
            }

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

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

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

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

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

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

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

            return(DocumentFormat.Pdf);
        }
Exemple #2
0
 public override bool IsContentSupported(STORAGE.Node content)
 {
     return(PreviewImageGenerator.IsSupportedExtension(ContentNamingProvider.GetFileExtension(content.Name)));
 }
Exemple #3
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);
        }