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); }
public void CreateImageMap(PPTXSlide SlideContent, SlidePart slidePart1, int slidePartChildLastIndex) { this.SlideContent = SlideContent; ImageIDMap.Clear(); for (int i = 0; i < SlideContent.Images.Count; ++i) { var imageFilePath = SlideContent.Images[i].ImageFilePath; if (System.IO.File.Exists(imageFilePath) == false) { continue; } if (ImageIDMap.ContainsKey(imageFilePath)) { continue; } var fileExt = Path.GetExtension(imageFilePath).ToLower(); var mime = "text/plain"; switch (fileExt) { case ".png": mime = "image/png"; break; case ".jpeg": case ".jpg": mime = "image/jpeg"; break; case ".bmp": mime = "image/bmp"; break; case ".gif": mime = "image/gif"; break; } var imageID = $"rId{i + slidePartChildLastIndex}"; ImagePart imagePart1 = slidePart1.AddNewPart <ImagePart>(mime, imageID); using (System.IO.FileStream stream = new System.IO.FileStream(imageFilePath, FileMode.Open)) { imagePart1.FeedData(stream); } ImageIDMap.Add(imageFilePath, imageID); } }
public void EndSheet(PPTXSlide CurrentSheet = null) { var _CurrentSheet = CurrentSheet ?? currentSlide; if (Settings.StackLayoutRule == EPPTXSideStackLayoutRule.Center) { var slideCenterY = PageHeight / 2.0f; var contentCentetY = ((LastAddedItemTransform.PositionY + LastAddedItemTransform.SizeY) - Settings.Margin.Top) / 2.0f + Settings.Margin.Top; var diffY = slideCenterY - contentCentetY; _CurrentSheet.TextAreas.ForEach(_textArea => _textArea.Transform.PositionY += diffY); _CurrentSheet.Tables.ForEach(_table => _table.Transform.PositionY += diffY); var slideCenterX = PageWidth / 2.0f; _CurrentSheet.Images.ForEach(_image => { var diffX = slideCenterX - (_image.Transform.PositionX + _image.Transform.SizeX / 2); _image.Transform.PositionX += diffX; _image.Transform.PositionY += diffY; }); } }
public PPTXSlide CreateNewSlide() { if (currentSlide != null) { EndSheet(currentSlide); } currentSlide = new PPTXSlide() { SlideLayout = EPPTXSlideLayoutType.BlankSheet }; document.Slides.Add(currentSlide); FontStack.Clear(); LastAddedItemTransform = new PPTXTransform(); LastAddedItemTransform.SizeY = Settings.Margin.Top; TextManager.Init(this); TableManager.Init(this); return(currentSlide); }
public SlideWriter(PPTXSlide SlideContent, PPTXSlideLayoutGroup SlideLayouts) { this.SlideContent = SlideContent; this.SlideLayouts = SlideLayouts; }