Example #1
0
        private void ShapeIsPicture(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape)
        {
            EImageContent eImage = new EImageContent();

            eImage.Name       = "Image";
            eImage.ID         = _idShape;
            eImage.Width      = _shape.Width * Utils.tlw;
            eImage.Height     = _shape.Height * Utils.tlh;
            eImage.Top        = _shape.Top * Utils.tlh;
            eImage.Left       = _shape.Left * Utils.tlw;
            eImage.Angle      = _shape.Rotation;
            eImage.ZOder      = (int)_shape.ZOrderPosition;
            eImage.Animations = _animation;
            eImage.RectCrop   = new ESuperPoint();
            var lstPic = Utils.slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p);

            P.Picture picTag    = GetPictureTag(lstPic, _shape.Id.ToString());
            string    rID       = picTag.BlipFill.Blip.Embed.Value;
            ImagePart part      = (ImagePart)Utils.slidePart.GetPartById(rID);
            string    pathImage = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(part.Uri.ToString()));

            Utils.CopyStream(part.GetStream(), pathImage);
            eImage.Image      = new Image();
            eImage.Image.Path = pathImage;
            _page.Children.Add(eImage);
        }
Example #2
0
        /// <summary>
        /// Nhập đối tượng là audio
        /// </summary>
        /// <param name="_page"></param>
        /// <param name="_shape"></param>
        private void ShapeIsAudio(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape)
        {
            EAudioElement eAudio = new EAudioElement();

            eAudio.Name       = "Audio";
            eAudio.ID         = _idShape;
            eAudio.Width      = _shape.Width * Utils.tlw;
            eAudio.Height     = _shape.Height * Utils.tlh;
            eAudio.Top        = _shape.Top * Utils.tlh;
            eAudio.Left       = _shape.Left * Utils.tlw;
            eAudio.Angle      = _shape.Rotation;
            eAudio.ZOder      = (int)_shape.ZOrderPosition;
            eAudio.Animations = _animation;
            //Lấy file audio trong gói sử dụng openxml
            var lstPic = Utils.slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p);

            P.Picture                     audioTag      = GetPictureTag(lstPic, _shape.Id.ToString());
            var                           audioFromFile = audioTag.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.Descendants <D.AudioFromFile>().Select(p => p);
            ReferenceRelationship         relationship  = Utils.slidePart.GetReferenceRelationship(audioFromFile.First().Link.Value);
            DataPartReferenceRelationship data          = (DataPartReferenceRelationship)relationship;
            string                        pathAudio     = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(data.Uri.ToString()));

            Utils.CopyStream(data.DataPart.GetStream(), pathAudio);
            eAudio.AudioFileName      = new Core.Model.Media.Audio();
            eAudio.AudioFileName.Path = pathAudio;
            _page.Children.Add(eAudio);
        }
Example #3
0
 internal SlidePicture(
     SCSlide slide,
     string blipRelateId,
     ShapeContext spContext,
     P.Picture pPicture) : base(slide, pPicture)
 {
     Image   = new SCImage(Slide.SlidePart, blipRelateId);
     Context = spContext;
 }
Example #4
0
 public static P.NonVisualDrawingProperties GetNonVisualDrawingProperties(
     this OpenXmlCompositeElement compositeElement)
 {
     // Get <p:cNvSpPr>
     return(compositeElement switch
     {
         P.GraphicFrame pGraphicFrame => pGraphicFrame.NonVisualGraphicFrameProperties
         .NonVisualDrawingProperties,
         P.Shape pShape => pShape.NonVisualShapeProperties.NonVisualDrawingProperties,
         P.Picture pPicture => pPicture.NonVisualPictureProperties.NonVisualDrawingProperties,
         P.GroupShape pGroupShape => pGroupShape.NonVisualGroupShapeProperties.NonVisualDrawingProperties,
         _ => throw new ShapeCrawlerException()
     });
Example #5
0
        /// <summary>
        /// Nhập đối tượng là video
        /// </summary>
        /// <param name="_page"></param>
        /// <param name="_shape"></param>
        private void ShapeIsVideo(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape)
        {
            var lstPic = Utils.slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p);

            P.Picture             videoTag      = GetPictureTag(lstPic, _shape.Id.ToString());
            var                   videoFromFile = videoTag.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.Descendants <D.VideoFromFile>().Select(p => p);
            ReferenceRelationship relationship  = Utils.slidePart.GetReferenceRelationship(videoFromFile.First().Link.Value);

            if (videoTag.NonVisualPictureProperties.NonVisualDrawingProperties.HyperlinkOnClick == null)
            {
                VideoAsFlash(_page, _shape, relationship, _animation, _idShape);
            }
            else
            {
                EVideoPlayer eVideoPlayer = new EVideoPlayer();
                eVideoPlayer.Name       = "Video";
                eVideoPlayer.ID         = _idShape;
                eVideoPlayer.Angle      = _shape.Rotation;
                eVideoPlayer.Width      = _shape.Width * Utils.tlw;
                eVideoPlayer.Height     = _shape.Height * Utils.tlh;
                eVideoPlayer.Top        = _shape.Top * Utils.tlh;
                eVideoPlayer.Left       = _shape.Left * Utils.tlw;
                eVideoPlayer.ZOder      = _shape.ZOrderPosition;
                eVideoPlayer.Animations = _animation;
                //Lấy file video trong gói sử dụng openxml
                DataPartReferenceRelationship data = (DataPartReferenceRelationship)relationship;
                string pathVideo = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(data.Uri.ToString()));
                Utils.CopyStream(data.DataPart.GetStream(), pathVideo);
                eVideoPlayer.Source      = new Core.Model.Media.Video();
                eVideoPlayer.Source.Path = pathVideo;
                //Lấy avata video
                eVideoPlayer.ImageFirst = new Image();
                string      rId       = videoTag.BlipFill.Blip.Embed.Value;
                OpenXmlPart avtPart   = Utils.slidePart.GetPartById(rId);
                string      pathAvata = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(avtPart.Uri.ToString()));
                Utils.CopyStream(avtPart.GetStream(), pathAvata);
                eVideoPlayer.ImageFirst.Path = pathAvata;
                _page.Children.Add(eVideoPlayer);
            }
        }
        public static void AddImage(string file, string image)
        {
            using (var presentation = PresentationDocument.Open(file, true))
            {
                var slidePart = presentation
                                .PresentationPart
                                .SlideParts
                                .ElementAt(u);
                //.First();

                var part = slidePart
                           .AddImagePart(ImagePartType.Png);

                using (var stream = File.OpenRead(image))
                {
                    part.FeedData(stream);
                }

                var tree = slidePart
                           .Slide
                           .Descendants <DocumentFormat.OpenXml.Presentation.ShapeTree>()
                           .First();

                var picture = new DocumentFormat.OpenXml.Presentation.Picture();

                picture.NonVisualPictureProperties = new DocumentFormat.OpenXml.Presentation.NonVisualPictureProperties();
                picture.NonVisualPictureProperties.Append(new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties
                {
                    Name = "My Shape",
                    Id   = (UInt32)tree.ChildElements.Count - 1
                });

                var nonVisualPictureDrawingProperties = new DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties();
                nonVisualPictureDrawingProperties.Append(new DocumentFormat.OpenXml.Drawing.PictureLocks()
                {
                    NoChangeAspect = true
                });
                picture.NonVisualPictureProperties.Append(nonVisualPictureDrawingProperties);
                picture.NonVisualPictureProperties.Append(new DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties());

                var blipFill = new DocumentFormat.OpenXml.Presentation.BlipFill();
                var blip1    = new DocumentFormat.OpenXml.Drawing.Blip()
                {
                    Embed = slidePart.GetIdOfPart(part)
                };
                var blipExtensionList1 = new DocumentFormat.OpenXml.Drawing.BlipExtensionList();
                var blipExtension1     = new DocumentFormat.OpenXml.Drawing.BlipExtension()
                {
                    Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
                };
                var useLocalDpi1 = new DocumentFormat.OpenXml.Office2010.Drawing.UseLocalDpi()
                {
                    Val = false
                };
                useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
                blipExtension1.Append(useLocalDpi1);
                blipExtensionList1.Append(blipExtension1);
                blip1.Append(blipExtensionList1);
                var stretch = new DocumentFormat.OpenXml.Drawing.Stretch();
                stretch.Append(new DocumentFormat.OpenXml.Drawing.FillRectangle());
                blipFill.Append(blip1);
                blipFill.Append(stretch);
                picture.Append(blipFill);

                picture.ShapeProperties             = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
                picture.ShapeProperties.Transform2D = new DocumentFormat.OpenXml.Drawing.Transform2D();
                picture.ShapeProperties.Transform2D.Append(new DocumentFormat.OpenXml.Drawing.Offset
                {
                    X = 0,
                    Y = 0,
                });
                picture.ShapeProperties.Transform2D.Append(new DocumentFormat.OpenXml.Drawing.Extents
                {
                    Cx = 1000000,
                    Cy = 1000000,
                });
                picture.ShapeProperties.Append(new DocumentFormat.OpenXml.Drawing.PresetGeometry
                {
                    Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle
                });

                tree.Append(picture);
            }
        }
Example #7
0
 internal LayoutPicture(SCSlideLayout slideLayout, P.Picture pPicture)
     : base(slideLayout, pPicture)
 {
 }
Example #8
0
 public MasterPicture(SCSlideMaster slideMaster, P.Picture pPicture)
     : base(slideMaster, pPicture)
 {
 }
Example #9
0
        internal static ShapeCollection CreateForSlideLayout(P.ShapeTree pShapeTree, SCSlideLayout slideLayout)
        {
            var shapeList = new List <IShape>();

            foreach (OpenXmlCompositeElement compositeElement in pShapeTree.OfType <OpenXmlCompositeElement>())
            {
                switch (compositeElement)
                {
                case P.Shape pShape:
                    shapeList.Add(new LayoutAutoShape(slideLayout, pShape));
                    continue;

                case P.GraphicFrame pGraphicFrame:
                {
                    A.GraphicData aGraphicData =
                        pGraphicFrame.GetFirstChild <A.Graphic>().GetFirstChild <A.GraphicData>();
                    if (aGraphicData.Uri.Value.Equals("http://schemas.openxmlformats.org/presentationml/2006/ole",
                                                      StringComparison.Ordinal))
                    {
                        shapeList.Add(new LayoutOLEObject(slideLayout, pGraphicFrame));
                        continue;
                    }

                    if (aGraphicData.Uri.Value.Equals("http://schemas.openxmlformats.org/drawingml/2006/chart",
                                                      StringComparison.Ordinal))
                    {
                        shapeList.Add(new LayoutChart(slideLayout, pGraphicFrame));
                        continue;
                    }

                    if (aGraphicData.Uri.Value.Equals("http://schemas.openxmlformats.org/drawingml/2006/table",
                                                      StringComparison.Ordinal))
                    {
                        shapeList.Add(new LayoutTable(slideLayout, pGraphicFrame));
                        continue;
                    }

                    break;
                }
                }

                // OLE Objects should be parsed before pictures, since OLE containers can contain p:pic elements,
                // thus OLE objects can be parsed as a picture by mistake.
                P.Picture pPicture;
                if (compositeElement is P.Picture treePicture)
                {
                    pPicture = treePicture;
                }
                else
                {
                    P.Picture framePicture = compositeElement.Descendants <P.Picture>().FirstOrDefault();
                    pPicture = framePicture;
                }

                if (pPicture != null)
                {
                    shapeList.Add(new LayoutPicture(slideLayout, pPicture));
                }
            }

            return(new ShapeCollection(shapeList));
        }
Example #10
0
        private static void AddImage(string file, List <ImagePath> image)
        {
            using (var presentationDocument = PresentationDocument.Open(file, true))
            {
                var                slideCount       = presentationDocument.PresentationPart.SlideParts.Count();
                SlideIdList        slideIdList      = presentationDocument.PresentationPart.Presentation.SlideIdList;
                Presentation       presentation     = presentationDocument.PresentationPart.Presentation;
                PresentationPart   presentationPart = presentationDocument.PresentationPart;
                OpenXmlElementList slideIds         = presentationPart.Presentation.SlideIdList.ChildElements;

                int cnt = 0;             // 画像の添付数

                int       j         = 0; // 画像添付スライド位置
                string    relId     = (slideIds[j] as SlideId).RelationshipId;
                SlidePart slidePart = (SlidePart)presentationPart.GetPartById(relId);

                foreach (ImagePath imgPath in image)
                {
                    ImagePart part = slidePart
                                     .AddImagePart(ImagePartType.Png);

                    using (var stream = File.OpenRead(imgPath.Path))
                    {
                        part.FeedData(stream);
                    }
                    var tree = slidePart
                               .Slide
                               .Descendants <DocumentFormat.OpenXml.Presentation.ShapeTree>()
                               .First();
                    var picture = new DocumentFormat.OpenXml.Presentation.Picture();


                    picture.NonVisualPictureProperties = new DocumentFormat.OpenXml.Presentation.NonVisualPictureProperties();
                    picture.NonVisualPictureProperties.Append(new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties
                    {
                        Name = "My Shape",
                        Id   = (UInt32)tree.ChildElements.Count - 1
                    });

                    var nonVisualPictureDrawingProperties = new DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties();
                    nonVisualPictureDrawingProperties.Append(new Drawing2.PictureLocks()
                    {
                        NoChangeAspect = true
                    });
                    picture.NonVisualPictureProperties.Append(nonVisualPictureDrawingProperties);
                    picture.NonVisualPictureProperties.Append(new DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties());

                    var blipFill = new DocumentFormat.OpenXml.Presentation.BlipFill();
                    var blip1    = new Drawing2.Blip()
                    {
                        Embed = slidePart.GetIdOfPart(part)
                    };
                    var blipExtensionList1 = new Drawing2.BlipExtensionList();
                    var blipExtension1     = new Drawing2.BlipExtension()
                    {
                        Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
                    };
                    var useLocalDpi1 = new DocumentFormat.OpenXml.Office2010.Drawing.UseLocalDpi()
                    {
                        Val = false
                    };
                    useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
                    blipExtension1.Append(useLocalDpi1);
                    blipExtensionList1.Append(blipExtension1);
                    blip1.Append(blipExtensionList1);
                    var stretch = new Drawing2.Stretch();
                    stretch.Append(new Drawing2.FillRectangle());
                    blipFill.Append(blip1);
                    blipFill.Append(stretch);
                    picture.Append(blipFill);

                    picture.ShapeProperties             = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
                    picture.ShapeProperties.Transform2D = new Drawing2.Transform2D();

                    int rotation = 0;
                    switch (imgPath.Rot)
                    {
                    case RotateFlipType.RotateNoneFlipNone:
                        rotation = 0;
                        picture.ShapeProperties.Transform2D.Append(new Drawing2.Offset
                        {
                            X = POSITION0[cnt % 6].X,
                            Y = POSITION0[cnt % 6].Y,
                        });
                        break;

                    case RotateFlipType.Rotate180FlipNone:     // 時計回りに180度回転しているので、180度回転して戻す
                        rotation = 60000 * 180;
                        picture.ShapeProperties.Transform2D.Append(new Drawing2.Offset
                        {
                            X = POSITION0[cnt % 6].X,
                            Y = POSITION0[cnt % 6].Y,
                        });
                        break;

                    case RotateFlipType.Rotate90FlipNone:     // 時計回りに270度回転しているので、90度回転して戻す
                        rotation = 60000 * 90;
                        picture.ShapeProperties.Transform2D.Append(new Drawing2.Offset
                        {
                            X = POSITION90[cnt % 6].X,
                            Y = POSITION90[cnt % 6].Y,
                        });
                        break;

                    case RotateFlipType.Rotate270FlipNone:     // 時計回りに90度回転しているので、270度回転して戻す
                        rotation = 60000 * 270;
                        picture.ShapeProperties.Transform2D.Append(new Drawing2.Offset
                        {
                            X = POSITION90[cnt % 6].X,
                            Y = POSITION90[cnt % 6].Y,
                        });
                        break;

                    default:
                        rotation = 0;
                        picture.ShapeProperties.Transform2D.Append(new Drawing2.Offset
                        {
                            X = POSITION0[cnt % 6].X,
                            Y = POSITION0[cnt % 6].Y,
                        });
                        break;
                    }
                    picture.ShapeProperties.Transform2D.Rotation = rotation;

                    // 縦向き
                    picture.ShapeProperties.Transform2D.Append(new Drawing2.Extents
                    {
                        Cx = imgPath.Size.Width,
                        Cy = imgPath.Size.Height,
                    });

                    picture.ShapeProperties.Append(new Drawing2.PresetGeometry
                    {
                        Preset = Drawing2.ShapeTypeValues.Rectangle
                    });

                    tree.Append(picture);

                    if (cnt % 6 == 5)
                    {
                        if (j < slideCount - 1)
                        {
                            j++;
                            relId     = (slideIds[j] as SlideId).RelationshipId;
                            slidePart = (SlidePart)presentationPart.GetPartById(relId);
                        }
                        else
                        {
                            // 画像ループを抜ける
                            break;
                        }
                    }
                    cnt++;
                }

                // スライドを削除する
                for (int i = slideCount - 1; i > j; i--)
                {
                    //Console.WriteLine(i);
                    SlideId slideId    = slideIds[i] as SlideId;
                    string  slideRelId = slideId.RelationshipId;
                    slideIdList.RemoveChild(slideId);

                    if (presentation.CustomShowList != null)
                    {
                        // Iterate through the list of custom shows.
                        foreach (var customShow in presentation.CustomShowList.Elements <CustomShow>())
                        {
                            if (customShow.SlideList != null)
                            {
                                // Declare a link list of slide list entries.
                                LinkedList <SlideListEntry> slideListEntries = new LinkedList <SlideListEntry>();
                                foreach (SlideListEntry slideListEntry in customShow.SlideList.Elements())
                                {
                                    // Find the slide reference to remove from the custom show.
                                    if (slideListEntry.Id != null && slideListEntry.Id == slideRelId)
                                    {
                                        slideListEntries.AddLast(slideListEntry);
                                    }
                                }

                                // Remove all references to the slide from the custom show.
                                foreach (SlideListEntry slideListEntry in slideListEntries)
                                {
                                    customShow.SlideList.RemoveChild(slideListEntry);
                                }
                            }
                        }
                    }
                    presentation.Save();

                    SlidePart slidePart2 = presentationPart.GetPartById(slideRelId) as SlidePart;

                    presentationPart.DeletePart(slidePart2);
                }
            }
        }
        private void InitializePosition(SlidePart templateSlidePart)
        {
            _shpTrendBetter         = new Shape();
            _shpTrendBetter         = new Shape();
            _shpTrendSame           = new Shape();
            _shpNofillUpward        = new Shape();
            _shpFillDownWard        = new Shape();
            _shpHeading             = new Shape();
            _shpTitle               = new Shape();
            _shpNofillDiamond       = new Shape();
            _shpStatsDetail         = new DocumentFormat.OpenXml.Presentation.Picture();
            _shpHeadingIntegrated   = new Shape();
            _cshpNonCriticl         = new Shape();
            _cshpNonCriticlProgress = new Shape();
            _cshpPartialProgress    = new Shape();
            _cshpDotLine            = new ConnectionShape();
            _shptrendPosition       = new Shape();
            _cshpConnector          = new ConnectionShape();
            _shptrendPosition       = new Shape();
            _shpFillDiamond         = new Shape();
            _cshpLine               = new ConnectionShape();
            _cshpStatsLine          = new ConnectionShape();
            _shpPageDetails         = new Shape();
            _shpFooterDetails       = new Shape();

            Xdr.Table table = templateSlidePart.Slide.CommonSlideData.ShapeTree.
                              ChildElements.OfType <GraphicFrame>().FirstOrDefault().Graphic.GraphicData.
                              ChildElements.OfType <Xdr.Table>().FirstOrDefault();

            rows = table.ChildElements.OfType <Xdr.TableRow>().ToList();
            Xdr.TableRow table1 = new Xdr.TableRow();


            IList <Xdr.TableRow> rows1 = table.ChildElements.OfType <Xdr.TableRow>().ToList();

            temp = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("PositionBox", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();

            _shptemptriangle = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("arrowBox", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            tableDate        = templateSlidePart.Slide.CommonSlideData.ShapeTree.
                               ChildElements.OfType <GraphicFrame>().LastOrDefault().Graphic.GraphicData.
                               ChildElements.OfType <Xdr.Table>().FirstOrDefault();

            _shpPageDetails   = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("PageDetails", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpTrendBetter   = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("TrendBetter", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpTrendLowerd   = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("TrendWorsen", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpTrendSame     = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("TrendFlat", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpFillDownWard  = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("DarkUpward", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpNofillDiamond = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("NoFillDiamond", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpHeading       = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("Heading", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();

            _shpHeadingIntegrated   = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("headingintegrated", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpStatsDetail         = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <DocumentFormat.OpenXml.Presentation.Picture>().Where(item => (item.NonVisualPictureProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualPictureProperties.NonVisualDrawingProperties.Description.Value.Equals("StatsDetail", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpTitle               = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("Title", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpFillDiamond         = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("FillDiamond", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpNonCriticl         = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("NonCritical", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpFooterDetails       = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("FooterDetails", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpNonCriticlProgress = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("NonCriticalProgress", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shpContactDetails      = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("ContactDetails", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _intHeigt               = _cshpNonCriticl.ShapeProperties.Transform2D.Extents.Cy;
            _shpNofillUpward        = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("NoFillUpward", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpPartialProgress    = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("PartialProgress", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpDotLine            = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <ConnectionShape>().Where(item => (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("DotLineBlack", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpLine               = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <ConnectionShape>().Where(item => (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("line", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpConnector          = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <ConnectionShape>().Where(item => (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("Connector", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _cshpStatsLine          = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <ConnectionShape>().Where(item => (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualConnectionShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("StatsLine", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            _shptrendPosition       = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("trendPosition", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();

            Datespart(tableDate);
        }
Example #12
0
        private void insert(SlidePart slidePart, string imagePath, string imgIdx, uint uid)
        {
            P.Picture picture = new P.Picture();
            string    embedId = imgIdx;

            P.NonVisualPictureProperties nonVisualPictureProperties = new P.NonVisualPictureProperties(
                new P.NonVisualDrawingProperties()
            {
                Id = uid--, Name = "Picture 5"
            },
                new P.NonVisualPictureDrawingProperties(new A.PictureLocks()
            {
                NoChangeAspect = true
            }),
                new ApplicationNonVisualDrawingProperties());
            P.BlipFill blipFill = new P.BlipFill();

            BlipExtensionList blipExtensionList = new BlipExtensionList();
            BlipExtension     blipExtension     = new BlipExtension()
            {
                Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
            };
            UseLocalDpi useLocalDpi = new UseLocalDpi()
            {
                Val = false
            };

            useLocalDpi.AddNamespaceDeclaration("a14",
                                                "http://schemas.microsoft.com/office/drawing/2010/main");

            blipExtension.Append(useLocalDpi);
            blipExtensionList.Append(blipExtension);
            Blip blip = new Blip()
            {
                Embed = embedId
            };

            blip.Append(blipExtensionList);

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

            stretch.Append(fillRectangle);

            blipFill.Append(blip);
            blipFill.Append(stretch);

            // TODO calc the size
            A.Transform2D transform2D = new A.Transform2D();
            A.Offset      offset      = new A.Offset()
            {
                X = 457200L, Y = 1524000L
            };
            A.Extents extents = new A.Extents()
            {
                Cx = 8229600L, Cy = 5029200L
            };
            transform2D.Append(offset);
            transform2D.Append(extents);

            A.PresetGeometry presetGeometry = new A.PresetGeometry()
            {
                Preset = A.ShapeTypeValues.Rectangle
            };
            A.AdjustValueList adjustValueList = new A.AdjustValueList();
            presetGeometry.Append(adjustValueList);

            P.ShapeProperties shapeProperties = new P.ShapeProperties();
            shapeProperties.Append(transform2D);
            shapeProperties.Append(presetGeometry);

            picture.Append(nonVisualPictureProperties);
            picture.Append(blipFill);
            picture.Append(shapeProperties);
            slidePart.Slide.CommonSlideData.ShapeTree.AppendChild(picture);

            var ext = System.IO.Path.GetExtension(imagePath).Substring(1);

            ext = ext.Equals("png", StringComparison.OrdinalIgnoreCase) ? "image/png" : "image/jpeg";
            ImagePart imagePart = slidePart.AddNewPart <ImagePart>(ext, embedId);

            using (FileStream fileStream = new FileStream(imagePath, FileMode.Open))
            {
                imagePart.FeedData(fileStream);
            }
        }
Example #13
0
        /// <summary>
        /// Use custom placeholder values from another file
        /// </summary>
        /// <param name="pDoc">oxml doc to change</param>
        public static void UseCustomNotesPageSize(string filename)
        {
            using (PresentationDocument document = PresentationDocument.Open(filename, true))
            {
                NoteSlideHelper nsh = GetNotesPageSizesFromFile();

                if (nsh.pNotesSz.Cx == 0)
                {
                    return;
                }

                // Get the presentation part of document
                PresentationPart presentationPart = document.PresentationPart;

                if (presentationPart != null)
                {
                    Presentation p = presentationPart.Presentation;

                    // Step 1 : Resize the presentation notesz prop
                    NotesSize defaultNotesSize = new NotesSize()
                    {
                        Cx = nsh.pNotesSz.Cx, Cy = nsh.pNotesSz.Cy
                    };

                    // first reset the notes size values
                    p.NotesSize = defaultNotesSize;

                    // now save up the part
                    p.Save();

                    // Step 2 : loop the shapes in the notes master and reset their sizes
                    if (Properties.Settings.Default.ResetNotesMaster == true)
                    {
                        // we need to reset sizes in the notes master for each shape
                        ShapeTree mSt = presentationPart.NotesMasterPart.NotesMaster.CommonSlideData.ShapeTree;

                        foreach (var mShp in mSt)
                        {
                            if (mShp.ToString() == StringResources.dfopShape)
                            {
                                PShape ps = (PShape)mShp;
                                NonVisualDrawingProperties nvdpr = ps.NonVisualShapeProperties.NonVisualDrawingProperties;
                                Transform2D t2d = ps.ShapeProperties.Transform2D;

                                if (nvdpr.Name.ToString().Contains(StringResources.pptHeaderPlaceholder))
                                {
                                    t2d.Offset.X   = nsh.t2dHeader.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dHeader.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dHeader.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dHeader.ExtentsCy;
                                }

                                if (nvdpr.Name.ToString().Contains(StringResources.pptDatePlaceholder))
                                {
                                    t2d.Offset.X   = nsh.t2dDate.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dDate.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dDate.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dDate.ExtentsCy;
                                }

                                if (nvdpr.Name.ToString().Contains(StringResources.pptSlideImagePlaceholder))
                                {
                                    t2d.Offset.X   = nsh.t2dSlideImage.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dSlideImage.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dSlideImage.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dSlideImage.ExtentsCy;
                                }

                                if (nvdpr.Name.ToString().Contains(StringResources.pptNotesPlaceholder))
                                {
                                    t2d.Offset.X   = nsh.t2dNotes.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dNotes.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dNotes.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dNotes.ExtentsCy;
                                }

                                if (nvdpr.Name.ToString().Contains(StringResources.pptFooterPlaceholder))
                                {
                                    t2d.Offset.X   = nsh.t2dFooter.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dFooter.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dFooter.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dFooter.ExtentsCy;
                                }

                                if (nvdpr.Name.ToString().Contains(StringResources.pptSlideNumberPlaceholder))
                                {
                                    t2d.Offset.X   = nsh.t2dSlideNumber.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dSlideNumber.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dSlideNumber.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dSlideNumber.ExtentsCy;
                                }

                                if (nvdpr.Name == StringResources.pptPicture)
                                {
                                    t2d.Offset.X   = nsh.t2dPicture.OffsetX;
                                    t2d.Offset.Y   = nsh.t2dPicture.OffsetY;
                                    t2d.Extents.Cx = nsh.t2dPicture.ExtentsCx;
                                    t2d.Extents.Cy = nsh.t2dPicture.ExtentsCy;
                                }
                            }
                        }

                        // Step 3 : we need to delete the size values for placeholders on each notes slide
                        foreach (var slideId in p.SlideIdList.Elements <SlideId>())
                        {
                            SlidePart            slidePart = presentationPart.GetPartById(slideId.RelationshipId) as SlidePart;
                            ShapeTree            st        = slidePart.NotesSlidePart.NotesSlide.CommonSlideData.ShapeTree;
                            List <RunProperties> rpList    = slidePart.NotesSlidePart.NotesSlide.Descendants <RunProperties>().ToList();

                            foreach (var s in st)
                            {
                                // we only want to make changes to the shapes
                                if (s.ToString() == StringResources.dfopShape)
                                {
                                    PShape ps = (PShape)s;
                                    NonVisualDrawingProperties nvdpr = ps.NonVisualShapeProperties.NonVisualDrawingProperties;
                                    Transform2D t2d = ps.ShapeProperties.Transform2D;

                                    if (t2d == null)
                                    {
                                        A.Transform2D t2dn    = new Transform2D();
                                        A.Offset      offset1 = new A.Offset()
                                        {
                                            X = 0L, Y = 0L
                                        };
                                        A.Extents extents1 = new A.Extents()
                                        {
                                            Cx = 0L, Cy = 0L
                                        };
                                        t2d         = t2dn;
                                        t2d.Offset  = offset1;
                                        t2d.Extents = extents1;
                                    }

                                    if (nvdpr.Name.ToString().Contains(StringResources.pptHeaderPlaceholder))
                                    {
                                        t2d.Offset.X   = nsh.t2dHeader.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dHeader.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dHeader.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dHeader.ExtentsCy;
                                    }

                                    if (nvdpr.Name.ToString().Contains(StringResources.pptDatePlaceholder))
                                    {
                                        t2d.Offset.X   = nsh.t2dDate.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dDate.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dDate.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dDate.ExtentsCy;
                                    }

                                    if (nvdpr.Name.ToString().Contains(StringResources.pptSlideImagePlaceholder))
                                    {
                                        t2d.Offset.X   = nsh.t2dSlideImage.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dSlideImage.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dSlideImage.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dSlideImage.ExtentsCy;
                                    }

                                    if (nvdpr.Name.ToString().Contains(StringResources.pptNotesPlaceholder))
                                    {
                                        t2d.Offset.X   = nsh.t2dNotes.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dNotes.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dNotes.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dNotes.ExtentsCy;
                                    }

                                    if (nvdpr.Name.ToString().Contains(StringResources.pptFooterPlaceholder))
                                    {
                                        t2d.Offset.X   = nsh.t2dFooter.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dFooter.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dFooter.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dFooter.ExtentsCy;
                                    }

                                    if (nvdpr.Name.ToString().Contains(StringResources.pptSlideNumberPlaceholder))
                                    {
                                        t2d.Offset.X   = nsh.t2dSlideNumber.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dSlideNumber.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dSlideNumber.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dSlideNumber.ExtentsCy;
                                    }
                                }
                                else if (s.ToString() == StringResources.dfopPresentationPicture)
                                {
                                    DocumentFormat.OpenXml.Presentation.Picture pic = (DocumentFormat.OpenXml.Presentation.Picture)s;
                                    Transform2D t2d = pic.ShapeProperties.Transform2D;

                                    // there are times when pictures get moved with the rest of the slide objects, need to reset those back
                                    if (t2d == null)
                                    {
                                        t2d.Offset.X   = nsh.t2dPicture.OffsetX;
                                        t2d.Offset.Y   = nsh.t2dPicture.OffsetY;
                                        t2d.Extents.Cx = nsh.t2dPicture.ExtentsCx;
                                        t2d.Extents.Cy = nsh.t2dPicture.ExtentsCy;
                                    }
                                    else
                                    {
                                        t2d.Offset.X   = 217831L;
                                        t2d.Offset.Y   = 4470109L;
                                        t2d.Extents.Cx = 3249763L;
                                        t2d.Extents.Cy = 2795946L;
                                    }
                                }
                            }

                            foreach (RunProperties r in rpList)
                            {
                                r.FontSize = 1200;
                            }
                        }
                    }

                    p.Save();
                }
            }
        }
Example #14
0
        /// <summary>
        /// Check the notes page size and reset values
        /// </summary>
        /// <param name="pDoc">oxml doc to change</param>
        public static void ChangeNotesPageSize(PresentationDocument pDoc)
        {
            if (pDoc == null)
            {
                throw new ArgumentNullException("pDoc = null");
            }

            // Get the presentation part of document
            PresentationPart presentationPart = pDoc.PresentationPart;

            if (presentationPart != null)
            {
                Presentation p = presentationPart.Presentation;

                // Step 1 : Resize the presentation notesz prop
                // if the notes size is already the default, no need to make any changes
                if (p.NotesSize.Cx != 6858000 || p.NotesSize.Cy != 9144000)
                {
                    // setup default size
                    NotesSize defaultNotesSize = new NotesSize()
                    {
                        Cx = 6858000L, Cy = 9144000L
                    };

                    // first reset the notes size values
                    p.NotesSize = defaultNotesSize;

                    // now save up the part
                    p.Save();
                }

                // Step 2 : loop the shapes in the notes master and reset their sizes
                // need to find a way to flag a file if the notes master and/or notes slides become corrupt
                // hiding behind a setting checkbox for now
                if (Properties.Settings.Default.ResetNotesMaster == true)
                {
                    // we need to reset sizes in the notes master for each shape
                    ShapeTree mSt = presentationPart.NotesMasterPart.NotesMaster.CommonSlideData.ShapeTree;

                    foreach (var mShp in mSt)
                    {
                        if (mShp.ToString() == StringResources.dfopShape)
                        {
                            PShape ps = (PShape)mShp;
                            NonVisualDrawingProperties nvdpr = ps.NonVisualShapeProperties.NonVisualDrawingProperties;
                            Transform2D t2d = ps.ShapeProperties.Transform2D;

                            // use default values
                            if (nvdpr.Name == StringResources.pptHeaderPlaceholder1)
                            {
                                t2d.Offset.X   = 0L;
                                t2d.Offset.Y   = 0L;
                                t2d.Extents.Cx = 2971800L;
                                t2d.Extents.Cy = 458788L;
                            }

                            if (nvdpr.Name == StringResources.pptDatePlaceholder2)
                            {
                                t2d.Offset.X   = 3884613L;
                                t2d.Offset.Y   = 0L;
                                t2d.Extents.Cx = 2971800L;
                                t2d.Extents.Cy = 458788L;
                            }

                            if (nvdpr.Name == StringResources.pptSlideImagePlaceholder3)
                            {
                                t2d.Offset.X   = 685800L;
                                t2d.Offset.Y   = 1143000L;
                                t2d.Extents.Cx = 5486400L;
                                t2d.Extents.Cy = 3086100L;
                            }

                            if (nvdpr.Name == StringResources.pptNotesPlaceholder4)
                            {
                                t2d.Offset.X   = 685800L;
                                t2d.Offset.Y   = 4400550L;
                                t2d.Extents.Cx = 5486400L;
                                t2d.Extents.Cy = 3600450L;
                            }

                            if (nvdpr.Name == StringResources.pptFooterPlaceholder5)
                            {
                                t2d.Offset.X   = 0L;
                                t2d.Offset.Y   = 8685213L;
                                t2d.Extents.Cx = 2971800L;
                                t2d.Extents.Cy = 458787L;
                            }

                            if (nvdpr.Name == StringResources.pptSlideNumberPlaceholder6)
                            {
                                t2d.Offset.X   = 3884613L;
                                t2d.Offset.Y   = 8685213L;
                                t2d.Extents.Cx = 2971800L;
                                t2d.Extents.Cy = 458787L;
                            }
                        }
                    }

                    // Step 3 : we need to delete the size values for placeholders on each notes slide
                    foreach (var slideId in p.SlideIdList.Elements <SlideId>())
                    {
                        SlidePart            slidePart = presentationPart.GetPartById(slideId.RelationshipId) as SlidePart;
                        ShapeTree            st        = slidePart.NotesSlidePart.NotesSlide.CommonSlideData.ShapeTree;
                        List <RunProperties> rpList    = slidePart.NotesSlidePart.NotesSlide.Descendants <RunProperties>().ToList();

                        foreach (var s in st)
                        {
                            // we only want to make changes to the shapes
                            if (s.ToString() == StringResources.dfopShape)
                            {
                                PShape      ps  = (PShape)s;
                                Transform2D t2d = ps.ShapeProperties.Transform2D;
                                TextBody    tb  = ps.TextBody;

                                // if the transform exists, delete it for each shape
                                if (t2d != null)
                                {
                                    t2d.Remove();
                                }

                                // if there are drawing paragraph props, reset the margin and indent to 0
                                if (ps.TextBody != null)
                                {
                                    foreach (var x in tb.ChildElements)
                                    {
                                        if (x.ToString() == "DocumentFormat.OpenXml.Drawing.Paragraph")
                                        {
                                            Paragraph para = (Paragraph)x;
                                            if (para.ParagraphProperties != null)
                                            {
                                                if (para.ParagraphProperties.LeftMargin != null)
                                                {
                                                    para.ParagraphProperties.LeftMargin = 0;
                                                }

                                                if (para.ParagraphProperties.Indent != null)
                                                {
                                                    para.ParagraphProperties.Indent = 0;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (s.ToString() == StringResources.dfopPresentationPicture)
                            {
                                DocumentFormat.OpenXml.Presentation.Picture pic = (DocumentFormat.OpenXml.Presentation.Picture)s;
                                Transform2D t2d = pic.ShapeProperties.Transform2D;

                                // there are times when pictures get moved with the rest of the slide objects, need to reset those back
                                if (t2d != null)
                                {
                                    t2d.Offset.X   = 217831L;
                                    t2d.Offset.Y   = 4470109L;
                                    t2d.Extents.Cx = 3249763L;
                                    t2d.Extents.Cy = 2795946L;
                                }
                            }
                        }

                        foreach (RunProperties r in rpList)
                        {
                            r.FontSize = 1200;
                        }
                    }
                }
            }
        }
Example #15
0
 public GeometryType ForPicture(P.Picture sdkPicture)
 {
     Check.NotNull(sdkPicture, nameof(sdkPicture));
     return(ForCompositeElement(sdkPicture, sdkPicture.ShapeProperties));
 }
Example #16
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();
        }
        /// <summary>
        /// Insert Image into Slide
        /// </summary>
        /// <param name="filePath">PowerPoint Path</param>
        /// <param name="imagePath">Image Path</param>
        /// <param name="imageExt">Image Extension</param>
        public void InsertImageInLastSlide(Slide slide, string imagePath, string imageExt)
        {
            // Creates a Picture instance and adds its children.
            P.Picture picture = new P.Picture();
            string    embedId = string.Empty;

            embedId = "rId" + (slide.Elements <P.Picture>().Count() + 915).ToString();
            P.NonVisualPictureProperties nonVisualPictureProperties = new P.NonVisualPictureProperties(
                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)4U, Name = "Picture 5"
            },
                new P.NonVisualPictureDrawingProperties(new D.PictureLocks()
            {
                NoChangeAspect = true
            }),
                new ApplicationNonVisualDrawingProperties());

            P.BlipFill blipFill = new P.BlipFill();
            Blip       blip     = new Blip()
            {
                Embed = embedId
            };

            // Creates a BlipExtensionList instance and adds its children
            BlipExtensionList blipExtensionList = new BlipExtensionList();
            BlipExtension     blipExtension     = new BlipExtension()
            {
                Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
            };

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

            useLocalDpi.AddNamespaceDeclaration("a14",
                                                "http://schemas.microsoft.com/office/drawing/2010/main");

            blipExtension.Append(useLocalDpi);
            blipExtensionList.Append(blipExtension);
            blip.Append(blipExtensionList);

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

            stretch.Append(fillRectangle);

            blipFill.Append(blip);
            blipFill.Append(stretch);

            // Creates a ShapeProperties instance and adds its children.
            P.ShapeProperties shapeProperties = new P.ShapeProperties();

            D.Transform2D transform2D = new D.Transform2D();
            D.Offset      offset      = new D.Offset()
            {
                X = 457200L, Y = 1524000L
            };
            D.Extents extents = new D.Extents()
            {
                Cx = 8229600L, Cy = 5029200L
            };

            transform2D.Append(offset);
            transform2D.Append(extents);

            D.PresetGeometry presetGeometry = new D.PresetGeometry()
            {
                Preset = D.ShapeTypeValues.Rectangle
            };
            D.AdjustValueList adjustValueList = new D.AdjustValueList();

            presetGeometry.Append(adjustValueList);

            shapeProperties.Append(transform2D);
            shapeProperties.Append(presetGeometry);

            picture.Append(nonVisualPictureProperties);
            picture.Append(blipFill);
            picture.Append(shapeProperties);

            slide.CommonSlideData.ShapeTree.AppendChild(picture);

            // Generates content of imagePart.
            ImagePart  imagePart  = slide.SlidePart.AddNewPart <ImagePart>(@"image/" + imageExt, embedId);
            FileStream fileStream = new FileStream(imagePath, FileMode.Open);

            imagePart.FeedData(fileStream);
            fileStream.Close();
        }
        public static void AddSvg(Stream stream, string svgPath, double percentageOfCy)
        {
            using PresentationDocument presentationDocument = PresentationDocument.Open(stream, true);
            PresentationPart presentationPart = presentationDocument.PresentationPart ??
                                                throw new InvalidOperationException(@"PresentationDocument is invalid.");

            // Get relationship ID of first slide.
            string sldRelId = presentationPart
                              .Presentation
                              .SlideIdList?
                              .Elements <Presentation.SlideId>()
                              .Select(slideId => (string)slideId.RelationshipId !)
                              .FirstOrDefault() ?? throw new InvalidOperationException(@"Presentation has no slides.");

            // Get first slide's part.
            var slidePart = (SlidePart)presentationPart.GetPartById(sldRelId);

            // Determine unique relationship IDs for new image parts.
            int    partsCount = slidePart.Parts.Count();
            string pngRelId   = $"rId{++partsCount}";
            string svgRelId   = $"rId{++partsCount}";

            // Add new image part with PNG image to slide part.
            using Stream pngStream = GeneralTools.ReadSvgAsPng(svgPath);
            GeneralTools.AddImagePart(slidePart, ImagePartType.Png, pngRelId, pngStream);

            // Add new image part with SVG image to slide part.
            using Stream svgStream = File.Open(svgPath, FileMode.Open, FileAccess.Read);
            GeneralTools.AddImagePart(slidePart, ImagePartType.Svg, svgRelId, svgStream);

            // Create markup.
            var picture =
                new Presentation.Picture(
                    new Presentation.NonVisualPictureProperties(
                        new Presentation.NonVisualDrawingProperties(
                            new Drawing.NonVisualDrawingPropertiesExtensionList(
                                new Drawing.Extension(
                                    new CreationId
            {
                Id = GeneralTools.GetNewGuidString(),
            }.WithNamespaceDeclaration("a16", "http://schemas.microsoft.com/office/drawing/2014/main"))
            {
                Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}",
            }))
            {
                Id   = (uint)++partsCount,
                Name = "Picture 1",
            },
                        new Presentation.NonVisualPictureDrawingProperties(
                            new Drawing.PictureLocks
            {
                NoChangeAspect = true,
            }),
                        new Presentation.ApplicationNonVisualDrawingProperties()),
                    new Presentation.BlipFill(
                        new Drawing.Blip(
                            new Drawing.BlipExtensionList(
                                new Drawing.Extension(
                                    new SVGBlip
            {
                Embed = svgRelId,
            })
            {
                Uri = "{96DAC541-7B7A-43D3-8B79-37D633B846F1}",
            }))
            {
                Embed = pngRelId,
            },
                        new Drawing.Stretch(
                            new Drawing.FillRectangle())),
                    GetShapeProperties(presentationPart, percentageOfCy));

            Presentation.ShapeTree shapeTree = slidePart
                                               .Slide
                                               .CommonSlideData?
                                               .ShapeTree ?? throw new InvalidOperationException();

            shapeTree.AppendChild(picture);
        }