Example #1
0
        /// <summary>
        /// Clones this slide.
        /// </summary>
        /// <returns>The clone.</returns>
        /// <remarks>
        /// <see href="http://blogs.msdn.com/b/brian_jones/archive/2009/08/13/adding-repeating-data-to-powerpoint.aspx">Adding Repeating Data to PowerPoint</see>
        /// <see href="http://startbigthinksmall.wordpress.com/2011/05/17/cloning-a-slide-using-open-xml-sdk-2-0/">Cloning a Slide using Open Xml SDK 2.0</see>
        /// <see href="http://www.exsilio.com/blog/post/2011/03/21/Cloning-Slides-including-Images-and-Charts-in-PowerPoint-presentations-Using-Open-XML-SDK-20-Productivity-Tool.aspx">See Cloning Slides including Images and Charts in PowerPoint presentations and Using Open XML SDK 2.0 Productivity Tool</see>
        /// </remarks>
        public PptxSlide Clone()
        {
            SlidePart slideTemplate = this.slidePart;

            // Clone slide contents
            SlidePart slidePartClone = this.presentationPart.AddNewPart <SlidePart>();

            using (var templateStream = slideTemplate.GetStream(FileMode.Open))
            {
                slidePartClone.FeedData(templateStream);
            }

            // Copy layout part
            slidePartClone.AddPart(slideTemplate.SlideLayoutPart);

            // Copy the image parts
            foreach (ImagePart image in slideTemplate.ImageParts)
            {
                ImagePart imageClone = slidePartClone.AddImagePart(image.ContentType, slideTemplate.GetIdOfPart(image));
                using (var imageStream = image.GetStream())
                {
                    imageClone.FeedData(imageStream);
                }
            }

            return(new PptxSlide(this.presentationPart, slidePartClone));
        }
Example #2
0
        private static StringBuilder GetSlideTitle(SlidePart slide)
        {
            var shapes = from shape in slide.Slide.Descendants <Shape>()
                         where IsTitleShape(shape)
                         select shape;
            StringBuilder paragraphTexttit   = new StringBuilder();
            string        paragraphSeparator = null;

            foreach (var shape in shapes)
            {
                // Get the text in each paragraph in this shape.
                foreach (var paragraph in shape.TextBody.Descendants <DocumentFormat.OpenXml.Drawing.Paragraph>())
                {
                    // Add a line break.
                    paragraphTexttit.Append(paragraphSeparator);

                    foreach (var text in paragraph.Descendants <DocumentFormat.OpenXml.Drawing.Text>())
                    {
                        paragraphTexttit.Append(text.Text);
                    }

                    paragraphSeparator = "\n";
                }
            }
            return(paragraphTexttit);
        }
Example #3
0
        private Slide insertSlide(PresentationPart presentationPart, string layoutName)
        {
            UInt32          slideId         = 256U;
            var             slideIdList     = presentationPart.Presentation.SlideIdList;
            SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First();
            SlideLayoutPart slideLayoutPart = slideMasterPart.SlideLayoutParts.First();

            if (slideIdList == null)
            {
                presentationPart.Presentation.SlideIdList = new SlideIdList();
                slideIdList = presentationPart.Presentation.SlideIdList;
            }

            slideId += Convert.ToUInt32(slideIdList.Count());
            Slide     slide     = new Slide(new CommonSlideData(new ShapeTree()));
            SlidePart slidePart = presentationPart.AddNewPart <SlidePart>();

            slide.Save(slidePart);

            slidePart.AddPart <SlideLayoutPart>(slideLayoutPart);
            slidePart.Slide.CommonSlideData = (CommonSlideData)slideLayoutPart.SlideLayout.CommonSlideData.Clone();
            SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild <SlideId>(new SlideId());

            newSlideId.Id             = slideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);

            return(getSlideByRelationShipId(presentationPart, newSlideId.RelationshipId));
        }
Example #4
0
        private void SetGraphicFrameNonVisualProperties(SlidePart slidePart, GraphicFrame gfarame)
        {
            if (gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnClick != null)
            {
                foreach (HyperlinkRelationship link in slidePart.HyperlinkRelationships)
                {
                    if (link.Id.Equals(gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnClick.Id))
                    {
                        ClickLinkUrl = link.Uri.IsAbsoluteUri ? link.Uri.AbsoluteUri : link.Uri.OriginalString;
                    }
                }
            }

            if (gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnHover != null)
            {
                foreach (HyperlinkRelationship link in slidePart.HyperlinkRelationships)
                {
                    if (link.Id.Equals(gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnHover.Id))
                    {
                        HoverLinkUrl = link.Uri.IsAbsoluteUri ? link.Uri.AbsoluteUri : link.Uri.OriginalString;
                    }
                }
            }

            var nonVisualShapeProp = new PPTNonVisualShapeProp
            {
                Id = "s1s" +                              //HARD CODED: we split it into separate HTML files!
                     gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.Id,
                Name = gfarame.LocalName,
                Type = "PPTGraphicFrame"
            };

            base.NonVisualShapeProp = nonVisualShapeProp;
        }
Example #5
0
        public static void GetSlideIdAndText(out int foundCounter, string searchString, Stream docName, int index)
        {
            using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
            {
                //Reset Counter for founded String
                int stringCount = 0;

                // Get the relationship ID of the first slide.
                PresentationPart   part     = ppt.PresentationPart;
                OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;

                string relId = (slideIds[index] as SlideId).RelationshipId;

                // Get the slide part from the relationship ID.
                SlidePart slide = (SlidePart)part.GetPartById(relId);

                // Build a StringBuilder object.
                StringBuilder paragraphText = new StringBuilder();

                // Get the inner text of the slide:
                IEnumerable <A.Text> texts = slide.Slide.Descendants <A.Text>();
                foreach (A.Text text in texts)
                {
                    if (text.Text.Contains(searchString) && searchString != "")
                    {
                        stringCount = stringCount + 1;
                    }
                }
                foundCounter = stringCount;
            }
        }
Example #6
0
        public void Generate(Partner partner, string quarter, SlidePart slide)
        {
            var list = GetData(partner.PartnerId, quarter);

            var tblList      = slide.Slide.Descendants <Table>().ToList();
            var tblMain      = tblList[0];
            var tblPlacement = tblList[1];

            var rows = tblMain.Descendants <TableRow>().ToList();

            var headerPlaceHolders = new Dictionary <string, string>();

            headerPlaceHolders.Add("varQuarter", quarter);
            PptHelper.ReplaceRowContent(rows[0], headerPlaceHolders);

            var templateRow = rows[1];

            foreach (var item in list)
            {
                var placeHolders = new Dictionary <string, string>();
                placeHolders.Add("varGoal", item.TargetedGoalName);
                placeHolders.Add("varPlan", item.QuarterPlan);
                placeHolders.Add("varPrevious", item.PreviousQuarter);
                placeHolders.Add("varWantToBe", item.TargetGoal);

                TableRow newRow = (TableRow)templateRow.Clone();
                PptHelper.ReplaceRowContent(newRow, placeHolders);

                tblMain.Append(newRow);
            }
            rows[1].Remove();

            GeneratePalcementTable(partner, quarter, tblPlacement);
        }
Example #7
0
        static void Main(string[] args)
        {
            using (var presentationDocument = DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(@"E:\lindexi\测试.pptx", false))
            {
                var presentationPart = presentationDocument.PresentationPart;
                var presentation     = presentationPart.Presentation;

                // 先获取页面
                var slideIdList = presentation.SlideIdList;

                foreach (var slideId in slideIdList.ChildElements.OfType <SlideId>())
                {
                    // 获取页面内容
                    SlidePart slidePart = (SlidePart)presentationPart.GetPartById(slideId.RelationshipId);

                    foreach (var paragraph in
                             slidePart.Slide
                             .Descendants <DocumentFormat.OpenXml.Drawing.Paragraph>())
                    {
                        // 获取段落
                        // 在 PPT 文本是放在形状里面
                        foreach (var text in
                                 paragraph.Descendants <DocumentFormat.OpenXml.Drawing.Text>())
                        {
                            // 获取段落文本,这样不会添加文本格式
                            Debug.WriteLine(text.Text);
                        }
                    }
                }
            }
        }
Example #8
0
        public static int CreateHyperLinkMap(PPTXSlide SlideContent, SlidePart slidePart1, Dictionary <string, string> HyperLinkIDMap)
        {
            int lastIndex = 2;

            var textRuns = SlideContent.TextAreas
                           .SelectMany(_textArea => _textArea.Texts.SelectMany(_text => _text.Texts))
                           .Where(_textRun => _textRun.Link.IsEnable)
                           .Select((_textRun, _Index) => new { Link = _textRun.Link, Index = _Index });

            foreach (var linkItem in textRuns)
            {
                if (HyperLinkIDMap.ContainsKey(linkItem.Link.LinkKey))
                {
                    continue;
                }

                var linkId = $"rId{linkItem.Index + 2}";
                lastIndex = linkItem.Index + 2;

                slidePart1.AddHyperlinkRelationship(new System.Uri(linkItem.Link.LinkURL, System.UriKind.Absolute), true, linkId);

                HyperLinkIDMap.Add(linkItem.Link.LinkKey, linkId);
            }

            return(lastIndex);
        }
Example #9
0
        /// <summary>
        /// Get the slideId and text for that slide
        /// </summary>
        /// <param name="sldText">string returned to caller</param>
        /// <param name="docName">path to powerpoint file</param>
        /// <param name="index">slide number</param>
        public static void GetSlideIdAndText(out string sldText, string docName, int index)
        {
            using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
            {
                // Get the relationship ID of the first slide.
                PresentationPart   part     = ppt.PresentationPart;
                OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;

                string relId = (slideIds[index] as SlideId).RelationshipId;

                // Get the slide part from the relationship ID.
                SlidePart slide = (SlidePart)part.GetPartById(relId);

                // Build a StringBuilder object.
                StringBuilder paragraphText = new StringBuilder();

                // Get the inner text of the slide:
                IEnumerable <A.Text> texts = slide.Slide.Descendants <A.Text>();
                foreach (A.Text text in texts)
                {
                    paragraphText.Append(text.Text);
                }
                sldText = paragraphText.ToString();
            }
        }
Example #10
0
        private string GetSlideTransitionsDuration(SlidePart slidePart)
        {
            string returnDuration = "0";

            try
            {
                Slide slide1 = slidePart.Slide;

                var transitions = slide1.Descendants <Transition>();
                foreach (var transition in transitions)
                {
                    if (transition.Duration != null && transition.Duration.HasValue)
                    {
                        return(transition.Duration);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                //Do nothing
            }

            return(returnDuration);
        }
Example #11
0
        public static void SetSlideID(PresentationPart presentationPart, SlidePart slidePart1)
        {
            // Insert the new slide into the slide list after the previous slide.
            SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;

            // Find the highest slide ID in the current list.
            uint    maxSlideId  = 1;
            SlideId prevSlideId = null;

            foreach (SlideId slideId in slideIdList.ChildElements)
            {
                if (slideId.Id > maxSlideId)
                {
                    maxSlideId  = slideId.Id;
                    prevSlideId = slideId;
                }
            }

            maxSlideId++;

            SlideId newSlideId = slideIdList.AppendChild(new SlideId());

            newSlideId.Id             = maxSlideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart1);
        }
Example #12
0
        private void GetSlideDurations(string powerPointFileName)
        {
            try
            {
                textBox.Text = "";
                TimeSpan presentationDuration = TimeSpan.FromSeconds(0);
                using (PresentationDocument pptDocument = PresentationDocument.Open(powerPointFileName, false))
                {
                    PresentationPart presentationPart = pptDocument.PresentationPart;
                    Presentation     presentation     = presentationPart.Presentation;
                    int slideNumber = 1;
                    foreach (var slideId in presentation.SlideIdList.Elements <SlideId>())
                    {
                        SlidePart slidePart = presentationPart.GetPartById(slideId.RelationshipId) as SlidePart;

                        var advanceAfterTimeDuration = ConvertStringToInt(GetSlideAdvanceAfterTimeDuration(slidePart));
                        var anitationsDuration       = GetSlideAnimationsDuration(slidePart);
                        var transitionDuration       = ConvertStringToInt(GetSlideTransitionsDuration(slidePart));

                        var      totalSlideDuration = advanceAfterTimeDuration + anitationsDuration + transitionDuration;
                        TimeSpan slideTime          = TimeSpan.FromMilliseconds(totalSlideDuration);
                        presentationDuration = presentationDuration.Add(slideTime);

                        textBox.Text += $"Slide {slideNumber} Total Duration: {totalSlideDuration} ms. (aat: {advanceAfterTimeDuration} ms, ani: {anitationsDuration} ms trn: {transitionDuration} ms)" + Environment.NewLine;
                        slideNumber++;
                    }

                    textBox.Text += $"Total Presentation Duration: {presentationDuration.TotalMilliseconds} msecs." + Environment.NewLine;
                }
            }
            catch (Exception ex)
            {
                textBox.Text = $"Problem occurred parsing file {powerPointFileName}.  Exception: {ex}";
            }
        }
        public static DocumentFormat.OpenXml.Presentation.Shape GetShapeByType(this PresentationDocument document, ShapeTypeValues shapeType)
        {
            var presentationPart = document.PresentationPart;
            var slideIdList      = presentationPart.Presentation.SlideIdList;

            foreach (var slideId in slideIdList.Elements <SlideId>())
            {
                SlidePart slidePart = (SlidePart)(presentationPart.GetPartById(slideId.RelationshipId.ToString()));

                if (slidePart != null)
                {
                    Slide slide = slidePart.Slide;
                    if (slide != null)
                    {
                        var shape = slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Shape>()
                                    .Where(x => x.ShapeProperties.Elements <PresetGeometry>().Any(p => p.Preset == shapeType))
                                    .FirstOrDefault();
                        if (shape != null)
                        {
                            return(shape);
                        }
                    }
                }
            }

            return(null);
        }
        public static DocumentFormat.OpenXml.Presentation.GraphicFrame GetGraphicFrameByName(this PresentationDocument document, string graphicFrameName)
        {
            var presentationPart = document.PresentationPart;
            var slideIdList      = presentationPart.Presentation.SlideIdList;

            foreach (var slideId in slideIdList.Elements <SlideId>())
            {
                SlidePart slidePart = (SlidePart)(presentationPart.GetPartById(slideId.RelationshipId.ToString()));

                if (slidePart != null)
                {
                    Slide slide = slidePart.Slide;
                    if (slide != null)
                    {
                        var chart = slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.GraphicFrame>()
                                    .Where(g => g.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.Name == graphicFrameName)
                                    .FirstOrDefault();
                        if (chart != null)
                        {
                            return(chart);
                        }
                    }
                }
            }

            return(null);
        }
Example #15
0
 public PictureHandler(ShapeContext.Builder shapeContextBuilder,
                       LocationParser transformFactory,
                       IGeometryFactory geometryFactory,
                       SlidePart sdkSldPart) :
     this(shapeContextBuilder, transformFactory, geometryFactory, sdkSldPart, new ShapeEx.Builder())
 {
 }
Example #16
0
        public static Slide GetDetailSlide(PresentationDocument _presentationDocument, int _slideIndex)
        {
            // Get the presentation part of the presentation document.
            presentationPart = _presentationDocument.PresentationPart;
            if (presentationPart != null && presentationPart.Presentation != null)
            {
                Presentation presentation = presentationPart.Presentation;
                if (presentation.SlideIdList != null)
                {
                    DocumentFormat.OpenXml.OpenXmlElementList slideIds = presentation.SlideIdList.ChildElements;

                    // If the slide ID is in range...
                    if (_slideIndex < slideIds.Count)
                    {
                        // Get the relationship ID of the slide.
                        string slidePartRelationshipId = (slideIds[_slideIndex] as SlideId).RelationshipId;

                        // Get the specified slide part from the relationship ID.
                        slidePart = (SlidePart)presentationPart.GetPartById(slidePartRelationshipId);
                        return(slidePart.Slide);
                    }
                }
            }
            return(null);
        }
Example #17
0
        // Replace text in PPT slide
        private void ReplaceTextMatchingAltText(PresentationDocument presentationDocument, string relationshipId)
        {
            OpenXmlElementList slideIds = presentationDocument.PresentationPart.Presentation.SlideIdList.ChildElements;

            foreach (SlideId sID in slideIds)      // loop thru the SlideIDList
            {
                string relId = sID.RelationshipId; // get first slide relationship
                if (relationshipId == relId)
                {
                    SlidePart slide = (SlidePart)presentationDocument.PresentationPart.GetPartById(relId); // Get the slide part from the relationship ID.

                    P.ShapeTree tree = slide.Slide.CommonSlideData.ShapeTree;
                    foreach (P.Shape shape in tree.Elements <P.Shape>())
                    {
                        // Run through all the paragraphs in the document
                        foreach (A.Paragraph paragraph in shape.Descendants().OfType <A.Paragraph>())
                        {
                            foreach (A.Run run in paragraph.Elements <A.Run>())
                            {
                                if (run.Text.InnerText.Contains("Name"))
                                {
                                    run.Text = new A.Text("Your new text");
                                }
                            }
                        }
                    }
                }
            }
        }
Example #18
0
 public SdkGroupShapeHandler(ShapeContext.Builder shapeContextBuilder,
                             InnerTransformFactory transformFactory,
                             IGeometryFactory geometryFactory,
                             SlidePart sdkSldPart) :
     this(shapeContextBuilder, transformFactory, geometryFactory, sdkSldPart, new ShapeEx.Builder())
 {
 }
Example #19
0
 public Builder(IPreSettings preSettings, PlaceholderFontService fontService, SlidePart sdkSldPart, IPlaceholderService placeholderService)
 {
     _preSettings        = preSettings ?? throw new ArgumentNullException(nameof(preSettings));
     _fontService        = fontService ?? throw new ArgumentNullException(nameof(fontService));
     _sdkSldPart         = sdkSldPart ?? throw new ArgumentNullException(nameof(sdkSldPart));
     _placeholderService = placeholderService;
 }
Example #20
0
        private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
        {
            SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1");

            P.SlideLayout slideLayout = new P.SlideLayout(
                new P.CommonSlideData(new P.ShapeTree(
                                          new P.NonVisualGroupShapeProperties(
                                              new P.NonVisualDrawingProperties()
            {
                Id = 1U, Name = string.Empty
            },
                                              new P.NonVisualGroupShapeDrawingProperties(),
                                              new P.ApplicationNonVisualDrawingProperties()),
                                          new P.GroupShapeProperties(new D.TransformGroup()),
                                          new P.Shape(
                                              new P.NonVisualShapeProperties(
                                                  new P.NonVisualDrawingProperties()
            {
                Id = 2U, Name = string.Empty
            },
                                                  new P.NonVisualShapeDrawingProperties(new D.ShapeLocks()
            {
                NoGrouping = true
            }),
                                                  new P.ApplicationNonVisualDrawingProperties(new P.PlaceholderShape())),
                                              new P.ShapeProperties(),
                                              new P.TextBody(
                                                  new D.BodyProperties(),
                                                  new D.ListStyle(),
                                                  new D.Paragraph(new D.EndParagraphRunProperties()))))),
                new P.ColorMapOverride(new D.MasterColorMapping()));
            slideLayoutPart1.SlideLayout = slideLayout;
            return(slideLayoutPart1);
        }
Example #21
0
        private void SetShapeVisualProperties(SlidePart slidePart, Shape shape)
        {
            if (shape.NonVisualShapeProperties.ApplicationNonVisualDrawingProperties.PlaceholderShape != null)
            {
                placeholder = shape.NonVisualShapeProperties.ApplicationNonVisualDrawingProperties.
                              PlaceholderShape;
                if (placeholder.Type == null)
                {
                    placeholder.Type = PlaceholderValues.Body;
                }
            }


            base.VisualShapeProp = new PPTVisualPPTShapeProp();
            base.SetSlideLayoutVisualShapeProperties(slidePart, shape);
            if (shape.ShapeProperties.Transform2D != null)
            {
                Int32Value rot = shape.ShapeProperties.Transform2D.Rotation;
                if (rot != null)
                {
                    double degrees = Math.Round(rot / RotationIndex);
                    if (degrees < 0)
                    {
                        degrees = 360 + degrees;
                    }
                    base.VisualShapeProp.Rotate = degrees;
                }

                base.VisualShapeProp.Extents = shape.ShapeProperties.Transform2D.Extents;
                base.VisualShapeProp.Offset  = shape.ShapeProperties.Transform2D.Offset;
            }
        }
Example #22
0
        public static ICollection <IEnumerable <string> > GetAllSlides(string path)
        {
            using (PresentationDocument presentationDocument = PresentationDocument.Open(path, false))
            {
                PresentationPart presentationPart = presentationDocument.PresentationPart;
                if (presentationPart != null && presentationPart.Presentation != null)
                {
                    Presentation presentation = presentationPart.Presentation;

                    if (presentation.SlideIdList != null)
                    {
                        var slideIds = presentation.SlideIdList.ChildElements;
                        ICollection <IEnumerable <string> > slides = new List <IEnumerable <string> >();

                        for (int i = 0; i < slideIds.Count; i++)
                        {
                            string    slidePartRelationshipId = (slideIds[i] as SlideId).RelationshipId;
                            SlidePart slidePart = (SlidePart)presentationPart.GetPartById(slidePartRelationshipId);

                            var slideText = GetAllTextInSlide(slidePart, i);
                            slides.Add(slideText);
                        }

                        return(slides);
                    }
                }

                return(null);
            }
        }
Example #23
0
 private void SetGraphicFrameVisualProperties(SlidePart slidePart,
                                              GraphicFrame gfarame)
 {
     base.VisualShapeProp = new PPTVisualPPTShapeProp();
     if (gfarame.Transform != null)
     {
         base.VisualShapeProp.Extents = gfarame.Transform.Extents;
         base.VisualShapeProp.Offset  = gfarame.Transform.Offset;
     }
     else
     {
         //Petco change get properties from layout for GraphicFrame object.
         DocumentFormat.OpenXml.Presentation.ShapeTree shapeTree =
             slidePart.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree;
         DocumentFormat.OpenXml.Presentation.GraphicFrame layoutShape;
         if (shapeTree != null)
         {
             layoutShape = shapeTree.GetFirstChild <DocumentFormat.OpenXml.Presentation.GraphicFrame>();
             if (layoutShape.Transform != null)
             {
                 base.VisualShapeProp.Extents = layoutShape.Transform.Extents;
                 base.VisualShapeProp.Offset  = layoutShape.Transform.Offset;
             }
         }
     }
 }
Example #24
0
        public bool ReplaceImageInSlide(SlidePart slidePart, string imageFileLocation)
        {
            this.Logger.Log("Trying to replace image in slide Part");
            var       mySlideLayoutPart = slidePart.SlideLayoutPart;
            ImagePart imagePart         = slidePart.AddImagePart("image/png");
            var       imgRelId          = slidePart.GetIdOfPart(imagePart);

            FileStream stream = new FileStream(imageFileLocation, FileMode.Open);

            imagePart.FeedData(stream);

            stream.Close();


            // https://blogs.msdn.microsoft.com/brian_jones/2008/11/18/creating-a-presentation-report-based-on-data/

            // Find the first image element and replace
            try
            {
                Drawing.Blip blip = slidePart.Slide.Descendants <Blip>().First();
                blip.Embed = imgRelId;
                this.Logger.Log("Saving slide Part");
                slidePart.Slide.Save();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public void ExtractTextFromPresentation(PresentationDocument document, StringBuilder sb)
        {
            PresentationPart pPart = document.PresentationPart;

            int slidesCount = 0;

            if (pPart != null)
            {
                slidesCount = pPart.SlideParts.Count();
            }

            if (slidesCount < 1)
            {
                return;
            }

            OpenXmlElementList slideIds = pPart.Presentation.SlideIdList.ChildElements;

            for (var i = 0; i < slidesCount; i++)
            {
                string relId = (slideIds[i] as SlideId).RelationshipId;

                SlidePart slide = (SlidePart)pPart.GetPartById(relId);

                IEnumerable <A.Text> texts = slide.Slide.Descendants <A.Text>();
                foreach (A.Text text in texts)
                {
                    sb.Append(text.Text);
                    sb.Append(" ");
                }
            }
        }
Example #26
0
        public ShapeCollection(SlidePart sdkSldPart, IShapeFactory shapeFactory)
        {
            Check.NotNull(sdkSldPart, nameof(sdkSldPart));
            Check.NotNull(shapeFactory, nameof(shapeFactory));

            CollectionItems = shapeFactory.FromSldPart(sdkSldPart).ToList();
        }
Example #27
0
        private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
        {
            SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1");
            SlideLayout     slideLayout      = new SlideLayout(
                new CommonSlideData(new ShapeTree(
                                        new P.NonVisualGroupShapeProperties(
                                            new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                                            new P.NonVisualGroupShapeDrawingProperties(),
                                            new ApplicationNonVisualDrawingProperties()),
                                        new GroupShapeProperties(new TransformGroup()),
                                        new P.Shape(
                                            new P.NonVisualShapeProperties(
                                                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)2U, Name = ""
            },
                                                new P.NonVisualShapeDrawingProperties(new ShapeLocks()
            {
                NoGrouping = true
            }),
                                                new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
                                            new P.ShapeProperties(),
                                            new P.TextBody(
                                                new BodyProperties(),
                                                new ListStyle(),
                                                new Paragraph(new EndParagraphRunProperties()))))),
                new ColorMapOverride(new MasterColorMapping()));

            slideLayoutPart1.SlideLayout = slideLayout;
            return(slideLayoutPart1);
        }
Example #28
0
        private void SetSpecificProperties(SlidePart slidePart)
        {
            textStyles = slidePart.SlideLayoutPart.SlideMasterPart.SlideMaster.TextStyles;
            var groupShapeBuilder = new PPTContainerShapeBuilder();

            ContainerShape = groupShapeBuilder.GetPPTContainerShape(slidePart, this);
        }
        private void InsertTrend(SymbolType pstrTrendName, SlidePart pslidePart, int pintrowNomb, int weightage)
        {
            Shape newTrendShp = new Shape();

            if (pstrTrendName.Equals(SymbolType.TrendBetter))
            {
                newTrendShp = (Shape)_shpTrendBetter.Clone();
                newTrendShp.NonVisualShapeProperties.NonVisualDrawingProperties.Id = 500U + incrementId;
                pslidePart.Slide.CommonSlideData.ShapeTree.AppendChild(newTrendShp);
                newTrendShp.ShapeProperties.Transform2D.Offset.Y = _shptrendPosition.ShapeProperties.Transform2D.Offset.Y + _intcellHeight * (_intTaskhaving);
                newTrendShp.ShapeProperties.Transform2D.Offset.X = _shptrendPosition.ShapeProperties.Transform2D.Offset.X;
            }
            else if (pstrTrendName.Equals(SymbolType.TrendFlat))
            {
                newTrendShp = (Shape)_shpTrendSame.Clone();
                newTrendShp.NonVisualShapeProperties.NonVisualDrawingProperties.Id = 500U + incrementId;
                pslidePart.Slide.CommonSlideData.ShapeTree.AppendChild(newTrendShp);
                newTrendShp.ShapeProperties.Transform2D.Offset.Y = _shptrendPosition.ShapeProperties.Transform2D.Offset.Y + _intcellHeight * (_intTaskhaving);
                newTrendShp.ShapeProperties.Transform2D.Offset.X = _shptrendPosition.ShapeProperties.Transform2D.Offset.X;
            }
            else
            {
                newTrendShp = (Shape)_shpTrendLowerd.Clone();
                newTrendShp.NonVisualShapeProperties.NonVisualDrawingProperties.Id = 500U + incrementId;
                pslidePart.Slide.CommonSlideData.ShapeTree.AppendChild(newTrendShp);
                newTrendShp.ShapeProperties.Transform2D.Offset.Y = _shptrendPosition.ShapeProperties.Transform2D.Offset.Y + _intcellHeight * (_intTaskhaving);
                newTrendShp.ShapeProperties.Transform2D.Offset.X = _shptrendPosition.ShapeProperties.Transform2D.Offset.X;
            }

            incrementId++;
        }
        public IReadOnlyCollection <PresentationSlideNote> GetAllSlideNotes()
        {
            var comments = new List <PresentationSlideNote>();

            using (PresentationDocument presentationDocument = PresentationDocument.Open(this._filePath, false))
            {
                var         presentationPart = presentationDocument.PresentationPart;
                SlideIdList slideIdList      = presentationPart.Presentation.SlideIdList;
                uint        slideShowIndex   = 0;

                _logger.Verbose($"Getting notes from {slideIdList.Count()} slides");

                foreach (SlideId slideId in slideIdList.ChildElements)
                {
                    slideShowIndex++;
                    SlidePart slidePart = (SlidePart)presentationPart.GetPartById(slideId.RelationshipId);
                    var       notesText = slidePart.NotesSlidePart?.NotesSlide?.InnerText;

                    if (!string.IsNullOrWhiteSpace(notesText))
                    {
                        comments.Add(new PresentationSlideNote(slideId.Id?.Value, slideId.RelationshipId, notesText, slideShowIndex));
                    }
                    //slidePart.Parts.Select(rel => rel.)
                    // NotesSlidePart.NotesSlide.InnerXml:
                    // "<p:cSld xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\"><p:spTree><p:nvGrpSpPr><p:cNvPr id=\"1\" name=\"\" /><p:cNvGrpSpPr /><p:nvPr /></p:nvGrpSpPr><p:grpSpPr><a:xfrm xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:off x=\"0\" y=\"0\" /><a:ext cx=\"0\" cy=\"0\" /><a:chOff x=\"0\" y=\"0\" /><a:chExt cx=\"0\" cy=\"0\" /></a:xfrm></p:grpSpPr><p:sp><p:nvSpPr><p:cNvPr id=\"2\" name=\"Slide Image Placeholder 1\" /><p:cNvSpPr><a:spLocks noGrp=\"1\" noRot=\"1\" noChangeAspect=\"1\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:cNvSpPr><p:nvPr><p:ph type=\"sldImg\" /></p:nvPr></p:nvSpPr><p:spPr /></p:sp><p:sp><p:nvSpPr><p:cNvPr id=\"3\" name=\"Notes Placeholder 2\" /><p:cNvSpPr><a:spLocks noGrp=\"1\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:cNvSpPr><p:nvPr><p:ph type=\"body\" idx=\"1\" /></p:nvPr></p:nvSpPr><p:spPr /><p:txBody><a:bodyPr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:lstStyle xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:p xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:r><a:rPr lang=\"en-US\" dirty=\"0\" /><a:t>Hey there!</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:cNvPr id=\"4\" name=\"Slide Number Placeholder 3\" /><p:cNvSpPr><a:spLocks noGrp=\"1\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:cNvSpPr><p:nvPr><p:ph type=\"sldNum\" sz=\"quarter\" idx=\"5\" /></p:nvPr></p:nvSpPr><p:spPr /><p:txBody><a:bodyPr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:lstStyle xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:p xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:fld id=\"{8E72DC8C-08B2-4C1F-8F46-48208154C347}\" type=\"slidenum\"><a:rPr lang=\"en-US\" smtClean=\"0\" /><a:t>1</a:t></a:fld><a:endParaRPr lang=\"en-US\" /></a:p></p:txBody></p:sp></p:spTree><p:extLst><p:ext uri=\"{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}\"><p14:creationId xmlns:p14=\"http://schemas.microsoft.com/office/powerpoint/2010/main\" val=\"3488005250\" /></p:ext></p:extLst></p:cSld><p:clrMapOvr xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\"><a:masterClrMapping xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:clrMapOvr>"
                }
            }

            return(comments.AsReadOnly());
        }