Ejemplo n.º 1
0
        public string convert(String path, List <String> imgList)
        {
            if (imgList == null || imgList.Count <= 0)
            {
                throw new Exception("image list is empty");
            }

            ImageInfoUtils utils = new ImageInfoUtils();

            imgList = utils.filter(imgList);
            Size   max         = utils.getSize(imgList.First());
            String pptTempPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
                                                        , "Template\\template.pptx");

            Console.WriteLine(max);
            if (0 == max.Width || 0 == max.Height)
            {
                throw new Exception("image list are all invalid");
            }
            if (!File.Exists(pptTempPath))
            {
                throw new Exception("template file is not exists");
            }

            return(convert(path, pptTempPath, imgList, max));
        }
        private void fill(string filePath, List <string> list)
        {
            int  imgId = 915;
            Size max   = new ImageInfoUtils().listMaxPPTSize(list);

            using (PresentationDocument presentationDocument = PresentationDocument.Open(filePath, true))
            {
                PresentationPart presentationPart = presentationDocument.PresentationPart;

                // reset slide.size
                presentationPart.Presentation.SlideSize = new SlideSize()
                {
                    Cx = max.Width, Cy = max.Height, Type = SlideSizeValues.Custom
                };

                // fill
                foreach (string p in list)
                {
                    Slide slide = initSlide(presentationPart, imgId.ToString());
                    fill(slide, max, p, imgId++);
                    Console.WriteLine(String.Format("Insert image[{0}] to slide[{1}]", p, imgId));
                    slide.Save();
                }

                presentationDocument.PresentationPart.Presentation.Save();
                Console.WriteLine("Save PPTX");
            }
        }
Ejemplo n.º 3
0
        public string convert(String path, List <String> imgList)
        {
            ImageInfoUtils utils = new ImageInfoUtils();

            imgList = utils.filter(imgList);
            Size max = utils.listMaxSize(imgList);


            if (0 == max.Width || 0 == max.Height)
            {
                throw new Exception("image list are all invalid");
            }

            return(convert(path, imgList, max));
        }
        public string convert(String path, List <String> imgList, String tempPath)
        {
            // init
            ImageInfoUtils utils = new ImageInfoUtils();

            imgList = utils.filter(imgList);
            Size max = utils.listMaxPPTSize(imgList);

            tempPath = String.IsNullOrEmpty(tempPath) ? DEFAULT_TEMPLATE_PATH : tempPath;

            // check
            if (0 == max.Width || 0 == max.Height)
            {
                throw new Exception("The format of resource images is invalid");
            }
            if (!File.Exists(tempPath))
            {
                throw new Exception(String.Format("The pointed PPTX template[{0}] is not exists", tempPath));
            }

            return(convert(path, tempPath, imgList, max));
        }
Ejemplo n.º 5
0
        private void insert(string filePath, List <string> imgList)
        {
            int imgId = 915;
            //Size max = new ImageInfoUtils().listMaxPPTSize(imgList);
            Size max = new ImageInfoUtils().getPPTSize(imgList.First());

            using (PresentationDocument presentationDocument = PresentationDocument.Open(filePath, true))
            {
                PresentationPart presentationPart = presentationDocument.PresentationPart;
                presentationPart.Presentation.SlideSize = new SlideSize()
                {
                    Cx = max.Width, Cy = max.Height, Type = SlideSizeValues.Custom
                };

                foreach (string img in imgList)
                {
                    Slide slide = insertSlide(presentationPart, imgId.ToString());
                    insertImageInLastSlide(slide, max, img, imgId++);
                    slide.Save();
                }

                presentationDocument.PresentationPart.Presentation.Save();
            }
        }
Ejemplo n.º 6
0
        public string convert(String path, List <PPTPage> pageList)
        {
            ImageInfoUtils utils   = new ImageInfoUtils();
            List <String>  imgList = new List <string>();

            pageList.ForEach(p =>
            {
                imgList.Add(p.Cover);
            });
            imgList = utils.filter(imgList);
            Size   max         = utils.listMaxPPTSize(imgList);
            String pptTempPath = System.Environment.CurrentDirectory + "\\..\\..\\Template\\template.pptx";

            if (0 == max.Width || 0 == max.Height)
            {
                throw new Exception("image list are all invalid");
            }
            if (!File.Exists(pptTempPath))
            {
                throw new Exception("template file is not exists");
            }

            return(convert(path, pptTempPath, pageList, max));
        }
Ejemplo n.º 7
0
        private void insertImage(Slide slide, Size maxSize, string imagePath, int imgId)
        {
            P.Picture picture  = new P.Picture();
            string    embedId  = string.Empty;
            string    imageExt = getImageType(imagePath);
            Size      imgSize  = new ImageInfoUtils().getPPTSize(imagePath);

            embedId = "rId" + imgId.ToString();

            P.NonVisualPictureProperties nonVisualPictureProperties = new P.NonVisualPictureProperties(
                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)4U, Name = "Picture " + imgId
            },
                new P.NonVisualPictureDrawingProperties(new A.PictureLocks()
            {
                NoChangeAspect = true
            }),
                new P.ApplicationNonVisualDrawingProperties());
            picture.Append(nonVisualPictureProperties);

            UseLocalDpi useLocalDpi = new UseLocalDpi()
            {
                Val = false
            };

            useLocalDpi.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
            BlipExtension blipExtension = new BlipExtension()
            {
                Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
            };

            blipExtension.Append(useLocalDpi);
            BlipExtensionList blipExtensionList = new BlipExtensionList();

            blipExtensionList.Append(blipExtension);

            Stretch       stretch       = new Stretch();
            FillRectangle fillRectangle = new FillRectangle();

            stretch.Append(fillRectangle);

            P.ShapeProperties shapeProperties = new P.ShapeProperties()
            {
                Transform2D = new A.Transform2D()
                {
                    Offset = new A.Offset()
                    {
                        X = (maxSize.Width - imgSize.Width) / 2, Y = (maxSize.Height - imgSize.Height) / 2
                    },
                    Extents = new A.Extents()
                    {
                        Cx = imgSize.Width, Cy = imgSize.Height
                    }
                }
            };
            shapeProperties.Append(new A.PresetGeometry()
            {
                Preset = A.ShapeTypeValues.Rectangle, AdjustValueList = new A.AdjustValueList()
            });

            Blip blip = new Blip()
            {
                Embed = embedId
            };

            blip.Append(blipExtensionList);
            P.BlipFill blipFill = new P.BlipFill()
            {
                Blip = blip
            };
            blipFill.Append(stretch);
            picture.Append(blipFill);

            picture.Append(shapeProperties);

            slide.CommonSlideData.ShapeTree.AppendChild(picture);

            ImagePart  imagePart  = slide.SlidePart.AddNewPart <ImagePart>(imageExt, embedId);
            FileStream fileStream = new FileStream(imagePath, FileMode.Open);

            imagePart.FeedData(fileStream);
            fileStream.Close();
        }