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; slideLayoutPart1.SlideLayout.CommonSlideData.Name = "ChartsSlideLayout"; return(slideLayoutPart1); }
private static void CopyChart(string fromPresentation1, string toPresentation2) { using (PresentationDocument ppt1 = PresentationDocument.Open(fromPresentation1, false)) using (PresentationDocument ppt2 = PresentationDocument.Open(toPresentation2, true)) { SlideId fromSlideId = ppt1.PresentationPart.Presentation.SlideIdList.GetFirstChild <SlideId>(); string fromRelId = fromSlideId.RelationshipId; SlideId toSlideId = ppt2.PresentationPart.Presentation.SlideIdList.GetFirstChild <SlideId>(); string toRelId = fromSlideId.RelationshipId; SlidePart fromSlidePart = (SlidePart)ppt1.PresentationPart.GetPartById(fromRelId); SlidePart toSlidePart = (SlidePart)ppt2.PresentationPart.GetPartById(fromRelId); var graphFrame = fromSlidePart.Slide.CommonSlideData.ShapeTree.GetFirstChild <GraphicFrame>().CloneNode(true); GroupShapeProperties groupShapeProperties = toSlidePart.Slide.CommonSlideData.ShapeTree.GetFirstChild <GroupShapeProperties>(); toSlidePart.Slide.CommonSlideData.ShapeTree.InsertAfter(graphFrame, groupShapeProperties); ChartPart fromChartPart = fromSlidePart.ChartParts.First(); ChartPart toChartPart = toSlidePart.AddNewPart <ChartPart>("rId2"); using (StreamReader streamReader = new StreamReader(fromChartPart.GetStream())) using (StreamWriter streamWriter = new StreamWriter(toChartPart.GetStream(FileMode.Create))) { streamWriter.Write(streamReader.ReadToEnd()); } EmbeddedPackagePart fromEmbeddedPackagePart1 = fromChartPart.EmbeddedPackagePart; EmbeddedPackagePart toEmbeddedPackagePart1 = toChartPart.AddNewPart <EmbeddedPackagePart>("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "rId3"); using (StreamReader streamReader = new StreamReader(fromEmbeddedPackagePart1.GetStream())) toEmbeddedPackagePart1.FeedData(streamReader.BaseStream); } }
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); }
private static List <SlidePart> CreateImageSlideParts(PresentationPart presentationPart, List <SvgDocument> svgDocs) { int id = 256; string relId; SlideId newSlideId; SlideLayoutId newSlideLayoutId; uint uniqueId = GetMaxUniqueId(presentationPart); uint maxSlideId = GetMaxSlideId(presentationPart.Presentation.SlideIdList); // get first slide master part: template SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First(); List <SlidePart> slideParts = new List <SlidePart>(); for (int i = 0; i < svgDocs.Count; i++) { id++; using (MemoryStream ms = new MemoryStream()) { using (System.Drawing.Bitmap image = svgDocs[i].Draw()) { image.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); relId = "rId" + id; // add new slide part SlidePart slidePart = presentationPart.AddNewPart <SlidePart>(relId); // add image part to slide part ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Bmp, relId); imagePart.FeedData(ms); // add image slide CreateImageSlide(relId).Save(slidePart); // add slide layout part to slide part SlideLayoutPart slideLayoutPart = slidePart.AddNewPart <SlideLayoutPart>(); CreateSlideLayoutPart().Save(slideLayoutPart); slideMasterPart.AddPart(slideLayoutPart); slideLayoutPart.AddPart(slideMasterPart); uniqueId++; newSlideLayoutId = new SlideLayoutId(); newSlideLayoutId.RelationshipId = slideMasterPart.GetIdOfPart(slideLayoutPart); newSlideLayoutId.Id = uniqueId; slideMasterPart.SlideMaster.SlideLayoutIdList.Append(newSlideLayoutId); // add slide part to presentaion slide list maxSlideId++; newSlideId = new SlideId(); newSlideId.RelationshipId = relId; newSlideId.Id = maxSlideId; presentationPart.Presentation.SlideIdList.Append(newSlideId); } } } slideMasterPart.SlideMaster.Save(); return(slideParts); }
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); } }
private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart, string layoutIdx, uint uid) { SlideLayoutPart layoutPart = slidePart.AddNewPart <SlideLayoutPart>(layoutIdx); 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())))); layoutPart.SlideLayout = slideLayout; return(layoutPart); }
private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1) { SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1"); // Add to slide master list part. 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 Drawing.TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" }, new P.NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape())), new P.ShapeProperties(), new P.TextBody( new Drawing.BodyProperties(), new Drawing.ListStyle(), new Drawing.Paragraph(new Drawing.EndParagraphRunProperties())) ) ) ), new ColorMapOverride(new Drawing.MasterColorMapping()) ) { Type = SlideLayoutValues.Title }; slideLayoutPart1.SlideLayout = slideLayout; slideLayoutPart1.SlideLayout.Type = SlideLayoutValues.Title; return(slideLayoutPart1); }
// Adds a comment to the first slide of the presentation document. // The presentation document must contain at least one slide. private static void AddCommentToPresentation(string file, string initials, string name, string text) { using (PresentationDocument doc = PresentationDocument.Open(file, true)) { // Declare a CommentAuthorsPart object. CommentAuthorsPart authorsPart; // Verify that there is an existing comment authors part. if (doc.PresentationPart.CommentAuthorsPart == null) { // If not, add a new one. authorsPart = doc.PresentationPart.AddNewPart <CommentAuthorsPart>(); } else { authorsPart = doc.PresentationPart.CommentAuthorsPart; } // Verify that there is a comment author list in the comment authors part. if (authorsPart.CommentAuthorList == null) { // If not, add a new one. authorsPart.CommentAuthorList = new CommentAuthorList(); } // Declare a new author ID. uint authorId = 0; CommentAuthor author = null; // If there are existing child elements in the comment authors list... if (authorsPart.CommentAuthorList.HasChildren) { // Verify that the author passed in is on the list. var authors = authorsPart.CommentAuthorList.Elements <CommentAuthor>().Where(a => a.Name == name && a.Initials == initials); // If so... if (authors.Any()) { // Assign the new comment author the existing author ID. author = authors.First(); authorId = author.Id; } // If not... if (author == null) { // Assign the author passed in a new ID authorId = authorsPart.CommentAuthorList.Elements <CommentAuthor>().Select(a => a.Id.Value).Max(); } } // If there are no existing child elements in the comment authors list. if (author == null) { authorId++; // Add a new child element(comment author) to the comment author list. author = authorsPart.CommentAuthorList.AppendChild <CommentAuthor> (new CommentAuthor() { Id = authorId, Name = name, Initials = initials, ColorIndex = 0 }); } // Get the first slide, using the GetFirstSlide method. SlidePart slidePart1 = GetFirstSlide(doc); // Declare a comments part. SlideCommentsPart commentsPart; // Verify that there is a comments part in the first slide part. if (slidePart1.GetPartsOfType <SlideCommentsPart>().Count() == 0) { // If not, add a new comments part. commentsPart = slidePart1.AddNewPart <SlideCommentsPart>(); } else { // Else, use the first comments part in the slide part. commentsPart = slidePart1.GetPartsOfType <SlideCommentsPart>().First(); } // If the comment list does not exist. if (commentsPart.CommentList == null) { // Add a new comments list. commentsPart.CommentList = new CommentList(); } // Get the new comment ID. uint commentIdx = author.LastIndex == null ? 1 : author.LastIndex + 1; author.LastIndex = commentIdx; // Add a new comment. Comment comment = commentsPart.CommentList.AppendChild <Comment>( new Comment() { AuthorId = authorId, Index = commentIdx, DateTime = DateTime.Now }); // Add the position child node to the comment element. comment.Append( new Position() { X = 100, Y = 200 }, new Text() { Text = text }); // Save the comment authors part. authorsPart.CommentAuthorList.Save(); // Save the comments part. commentsPart.CommentList.Save(); } }
public static void InsertAnimatedModel3D(string pptxPath, string pngPath, string glbPath) { if (pptxPath == null) { throw new ArgumentNullException("pptxPath"); } if (pngPath == null) { throw new ArgumentNullException("pngPath"); } if (glbPath == null) { throw new ArgumentNullException("glbPath"); } // mc:AternateContent & p:timing // Open the presentation document using PresentationDocument presentationDocument = PresentationDocument.Open(pptxPath, true); // Get the relationship ID of the first slide. PresentationPart presentationPart = presentationDocument.PresentationPart; // Verify that the presentation part and presentation exist. if (presentationPart != null && presentationPart.Presentation != null) { OpenXmlElementList slideIds = presentationPart.Presentation.SlideIdList.ChildElements; if (slideIds.Count > 0) { string relId = (slideIds[0] as SlideId).RelationshipId; SlidePart slidePart = (SlidePart)presentationPart.GetPartById(relId); int partsCount = slidePart.Parts.Count(); // Add the .png and .glb files for the 3D image using FileStream glbFileStream = new FileStream(glbPath, FileMode.Open, FileAccess.Read); glbFileStream.Seek(0, SeekOrigin.Begin); string glbId = $"rId{++partsCount}"; Model3DReferenceRelationshipPart glbImagePart = slidePart.AddNewPart <Model3DReferenceRelationshipPart>(glbId); glbImagePart.FeedData(glbFileStream); using FileStream pngFileStream = new FileStream(pngPath, FileMode.Open, FileAccess.Read); pngFileStream.Seek(0, SeekOrigin.Begin); string pngId = $"rId{++partsCount}"; ImagePart pngImagePart = slidePart.AddImagePart(ImagePartType.Png, pngId); pngImagePart.FeedData(pngFileStream); CommonSlideData commonSlideDataPart = slidePart.RootElement.Descendants <CommonSlideData>().FirstOrDefault(); // Add an AlternateContent element to the shape tree AlternateContent alternateContent = commonSlideDataPart.ShapeTree.AppendChild(new AlternateContent()); // Add mc:Choice element to AlternateContent AlternateContentChoice alternateContentChoice = alternateContent.AppendChild(new AlternateContentChoice()); alternateContentChoice.Requires = "am3d"; alternateContentChoice.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d"); // Add mc:Fallback element to AlternateContent AlternateContentFallback alternateContentFallback = alternateContent.AppendChild(new AlternateContentFallback()); // Create a creationId with the correct namespace string guidId = "{" + System.Guid.NewGuid().ToString().ToUpper() + "}"; DocumentFormat.OpenXml.Office2016.Drawing.CreationId creationId = new DocumentFormat.OpenXml.Office2016.Drawing.CreationId(); creationId.AddNamespaceDeclaration("a16", "http://schemas.microsoft.com/office/drawing/2014/main"); creationId.Id = guidId; // Clone the creationId DocumentFormat.OpenXml.Office2016.Drawing.CreationId creationId2 = (DocumentFormat.OpenXml.Office2016.Drawing.CreationId)creationId.Clone(); string creationIdPartenId = guidId; UInt32Value threeDModelId = new UInt32Value(2U); // Create modId in with the correct namespace xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="3636546711" DocumentFormat.OpenXml.Office2010.PowerPoint.ModificationId modificationId = new DocumentFormat.OpenXml.Office2010.PowerPoint.ModificationId(); modificationId.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); modificationId.Val = 3636546711; // Create a aExtension in with the correct attributes DocumentFormat.OpenXml.Drawing.Extension aExtension = new DocumentFormat.OpenXml.Drawing.Extension(); aExtension.SetAttributes( new OpenXmlAttribute[] { new OpenXmlAttribute("cx", string.Empty, "4158691"), new OpenXmlAttribute("cy", string.Empty, "3460830"), }); // Create a clone of a:ext for am3d:spPr DocumentFormat.OpenXml.Drawing.Extension aExtension2 = (DocumentFormat.OpenXml.Drawing.Extension)aExtension.Clone(); // Create a a3damin:posterFrame and add the namespace DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.PosterFrame model3dPosterFrame = new DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.PosterFrame() { AnimId = 0 }; model3dPosterFrame.AddNamespaceDeclaration("a3danim", "http://schemas.microsoft.com/office/drawing/2018/animation/model3d"); // Create a clone of a:ext for p:spPr DocumentFormat.OpenXml.Drawing.Extension aExtension3 = (DocumentFormat.OpenXml.Drawing.Extension)aExtension.Clone(); // Create a:off DocumentFormat.OpenXml.Drawing.Offset offset = new DocumentFormat.OpenXml.Drawing.Offset() { X = 4016654, Y = 1698584 }; DocumentFormat.OpenXml.Drawing.Offset offset2 = (DocumentFormat.OpenXml.Drawing.Offset)offset.Clone(); // Create a3danim:embedAnim and assign its namespace DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.EmbeddedAnimation embeddedAnimation = new DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.EmbeddedAnimation() { AnimId = 0 }; embeddedAnimation.AddNamespaceDeclaration("a3danim", "http://schemas.microsoft.com/office/drawing/2018/animation/model3d"); embeddedAnimation.AppendChild(new DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.AnimationProperties() { Length = "1899", Count = "indefinite" }); // Create the mc:AlternateContent element alternateContentChoice.AppendChild( new GraphicFrame( new NonVisualGraphicFrameProperties( new NonVisualDrawingProperties( new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtensionList( new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtension( creationId) { Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}" })) { Id = threeDModelId, Name = "3D Model 1", Description = "Flying bee" }, new NonVisualGraphicFrameDrawingProperties(), new ApplicationNonVisualDrawingProperties( new ApplicationNonVisualDrawingPropertiesExtensionList( new ApplicationNonVisualDrawingPropertiesExtension( modificationId) { Uri = "{D42A27DB-BD31-4B8C-83A1-F6EECF244321}" }))), new Transform( offset, aExtension), new DocumentFormat.OpenXml.Drawing.Graphic( new DocumentFormat.OpenXml.Drawing.GraphicData( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3D( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ShapeProperties( new DocumentFormat.OpenXml.Drawing.Transform2D( new DocumentFormat.OpenXml.Drawing.Offset() { X = 0, Y = 0 }, aExtension2), new DocumentFormat.OpenXml.Drawing.PresetGeometry( new DocumentFormat.OpenXml.Drawing.AdjustValueList()) { Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DCamera( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D() { X = 0, Y = 0, Z = 67740115 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.UpVector3D() { Dx = 0, Dy = 36000000, Dz = 0 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.LookAtPoint3D() { X = 0, Y = 0, Z = 0 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PerspectiveProjection() { Fov = 2700000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DTransform( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.MeterPerModelUnitPositiveRatio() { N = 30569, D = 1000000 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PreTransVector3D() { Dx = -98394, Dy = -14223043, Dz = -1124542 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Scale3D( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.SxRatio() { Numerator = 1000000, Denominator = 1000000 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.SyRatio() { Numerator = 1000000, Denominator = 1000000 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.SzRatio() { Numerator = 1000000, Denominator = 1000000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Rotate3D(), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PostTransVector3D() { Dx = 0, Dy = 0, Dz = 0 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DRaster( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Blip() { Embed = pngId }) { RName = "Office3DRenderer", RVer = "16.0.8326" }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DExtensionList( new DocumentFormat.OpenXml.Drawing.Extension( embeddedAnimation) { Uri = "{9A65AA19-BECB-4387-8358-8AD5134E1D82}" }, new DocumentFormat.OpenXml.Drawing.Extension( model3dPosterFrame) { Uri = "{E9DE012E-A134-456F-84FE-255F9AAD75C6}" }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ObjectViewport() { ViewportSz = 5418666 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.AmbientLight( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType( new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage() { RedPortion = 50000, GreenPortion = 50000, BluePortion = 50000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IlluminancePositiveRatio() { N = 500000, D = 1000000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PointLight( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType( new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage() { RedPortion = 100000, GreenPortion = 75000, BluePortion = 50000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IntensityPositiveRatio() { N = 9765625, D = 1000000 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D() { X = 21959998, Y = 70920001, Z = 16344003 }) { Rad = 0 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PointLight( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType( new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage() { RedPortion = 40000, GreenPortion = 60000, BluePortion = 95000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IntensityPositiveRatio() { N = 12250000, D = 1000000 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D() { X = -37964106, Y = 51130435, Z = 57631972 }) { Rad = 0 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PointLight( new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType( new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage() { RedPortion = 86837, GreenPortion = 72700, BluePortion = 100000 }), new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IntensityPositiveRatio() { N = 3125000, D = 1000000 }, new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D() { X = -37739122, Y = 58056624, Z = -34769649 }) { Rad = 0 }) { Embed = glbId }) { Uri = "http://schemas.microsoft.com/office/drawing/2017/model3d" }))); // Add children to mc:Fallback alternateContentFallback.AppendChild( new DocumentFormat.OpenXml.Presentation.Picture( new NonVisualPictureProperties( new NonVisualDrawingProperties( new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtensionList( new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtension( creationId2) { Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}" })) { Id = threeDModelId, Name = "3D Model 1", Description = "Flying bee" }, new DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties( new DocumentFormat.OpenXml.Drawing.PictureLocks() { NoGrouping = true, NoRotation = true, NoChangeAspect = true, NoMove = true, NoResize = true, NoEditPoints = true, NoAdjustHandles = true, NoChangeArrowheads = true, NoChangeShapeType = true, NoCrop = true }), new DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties()), new DocumentFormat.OpenXml.Presentation.BlipFill( new DocumentFormat.OpenXml.Drawing.Blip() { Embed = pngId }, new DocumentFormat.OpenXml.Drawing.Stretch( new DocumentFormat.OpenXml.Drawing.FillRectangle())), new DocumentFormat.OpenXml.Presentation.ShapeProperties( new DocumentFormat.OpenXml.Drawing.Transform2D( offset2, aExtension3), new DocumentFormat.OpenXml.Drawing.PresetGeometry( new DocumentFormat.OpenXml.Drawing.AdjustValueList()) { Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle }))); // DocumentFormat.OpenXml.Presentation.AttributeName attributeName = new DocumentFormat.OpenXml.Presentation.AttributeName(); // attributeName.InnerXml = "embedded1"; // Append the p:timing to the p:sld slidePart.RootElement.AppendChild( new DocumentFormat.OpenXml.Presentation.Timing( new DocumentFormat.OpenXml.Presentation.TimeNodeList( new DocumentFormat.OpenXml.Presentation.ParallelTimeNode( new DocumentFormat.OpenXml.Presentation.CommonTimeNode( new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList( new DocumentFormat.OpenXml.Presentation.SequenceTimeNode( new DocumentFormat.OpenXml.Presentation.CommonTimeNode( new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList( new DocumentFormat.OpenXml.Presentation.ParallelTimeNode( new DocumentFormat.OpenXml.Presentation.CommonTimeNode( new DocumentFormat.OpenXml.Presentation.StartConditionList( new DocumentFormat.OpenXml.Presentation.Condition() { Delay = "indefinite" }, new DocumentFormat.OpenXml.Presentation.Condition( new DocumentFormat.OpenXml.Presentation.TimeNode() { Val = 2 }) { Event = DocumentFormat.OpenXml.Presentation.TriggerEventValues.OnBegin, Delay = "0" }), new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList( new DocumentFormat.OpenXml.Presentation.ParallelTimeNode( new DocumentFormat.OpenXml.Presentation.CommonTimeNode( new DocumentFormat.OpenXml.Presentation.StartConditionList( new DocumentFormat.OpenXml.Presentation.Condition() { Delay = "0" }), new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList( new DocumentFormat.OpenXml.Presentation.ParallelTimeNode( new DocumentFormat.OpenXml.Presentation.CommonTimeNode( new DocumentFormat.OpenXml.Presentation.StartConditionList( new DocumentFormat.OpenXml.Presentation.Condition() { Delay = "0" }), new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList( new DocumentFormat.OpenXml.Presentation.Animate( new DocumentFormat.OpenXml.Presentation.CommonBehavior( new DocumentFormat.OpenXml.Presentation.CommonTimeNode() { Id = 6, Duration = "1900", Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold }, new DocumentFormat.OpenXml.Presentation.TargetElement( new DocumentFormat.OpenXml.Presentation.ShapeTarget() { ShapeId = "2" }), new DocumentFormat.OpenXml.Presentation.AttributeNameList( new DocumentFormat.OpenXml.Presentation.AttributeName("embedded1"))), new DocumentFormat.OpenXml.Presentation.TimeAnimateValueList( new DocumentFormat.OpenXml.Presentation.TimeAnimateValue( new DocumentFormat.OpenXml.Presentation.VariantValue( new DocumentFormat.OpenXml.Presentation.FloatVariantValue() { Val = DocumentFormat.OpenXml.SingleValue.FromSingle(0) })) { Time = "0" }, new DocumentFormat.OpenXml.Presentation.TimeAnimateValue( new DocumentFormat.OpenXml.Presentation.VariantValue( new DocumentFormat.OpenXml.Presentation.FloatVariantValue() { Val = DocumentFormat.OpenXml.SingleValue.FromSingle(1) })) { Time = "100000" })) { CalculationMode = DocumentFormat.OpenXml.Presentation.AnimateBehaviorCalculateModeValues.Linear, ValueType = DocumentFormat.OpenXml.Presentation.AnimateBehaviorValues.Number })) { Id = 5, PresetId = 100, PresetClass = DocumentFormat.OpenXml.Presentation.TimeNodePresetClassValues.Emphasis, PresetSubtype = 1, RepeatCount = "indefinite", Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold, NodeType = DocumentFormat.OpenXml.Presentation.TimeNodeValues.WithEffect }))) { Id = 4, Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold }))) { Id = 3, Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold }))) { Id = 2, Duration = "indefinite", NodeType = DocumentFormat.OpenXml.Presentation.TimeNodeValues.MainSequence }, new DocumentFormat.OpenXml.Presentation.PreviousConditionList( new DocumentFormat.OpenXml.Presentation.Condition( new DocumentFormat.OpenXml.Presentation.TargetElement( new DocumentFormat.OpenXml.Presentation.SlideTarget())) { Event = DocumentFormat.OpenXml.Presentation.TriggerEventValues.OnPrevious, Delay = "0" }), new DocumentFormat.OpenXml.Presentation.NextConditionList( new DocumentFormat.OpenXml.Presentation.Condition( new DocumentFormat.OpenXml.Presentation.TargetElement( new DocumentFormat.OpenXml.Presentation.SlideTarget())) { Event = DocumentFormat.OpenXml.Presentation.TriggerEventValues.OnNext, Delay = "0" })) { Concurrent = true, NextAction = DocumentFormat.OpenXml.Presentation.NextActionValues.Seek })) { Id = 1, Duration = "indefinite", Restart = DocumentFormat.OpenXml.Presentation.TimeNodeRestartValues.Never, NodeType = DocumentFormat.OpenXml.Presentation.TimeNodeValues.TmingRoot })))); } } }
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); } }
public static void AddNote(string docName, int index) { try { string relId = "rId" + (index + 1); using (PresentationDocument ppt = PresentationDocument.Open(docName, false)) { PresentationPart part = ppt.PresentationPart; OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements; relId = (slideIds[index] as SlideId).RelationshipId; } using (PresentationDocument ppt = PresentationDocument.Open(docName, true)) { PresentationPart presentationPart1 = ppt.PresentationPart; SlidePart slidePart2 = (SlidePart)presentationPart1.GetPartById(relId); NotesSlidePart notesSlidePart1; string existingSlideNote = ""; if (slidePart2.NotesSlidePart != null) { //Appened new note to existing note. existingSlideNote = slidePart2.NotesSlidePart.NotesSlide.InnerText + "\n"; var val = (NotesSlidePart)slidePart2.GetPartById(relId); notesSlidePart1 = slidePart2.AddPart <NotesSlidePart>(val, relId); } else { //Add a new noteto a slide. notesSlidePart1 = slidePart2.AddNewPart <NotesSlidePart>(relId); } NotesSlide notesSlide = new NotesSlide( new CommonSlideData(new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new A.TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Slide Image Placeholder 1" }, new P.NonVisualShapeDrawingProperties(new A.ShapeLocks() { NoGrouping = true, NoRotation = true, NoChangeAspect = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.SlideImage })), new P.ShapeProperties()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "Notes Placeholder 2" }, new P.NonVisualShapeDrawingProperties(new A.ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Body, Index = (UInt32Value)1U })), new P.ShapeProperties(), new P.TextBody( new A.BodyProperties(), new A.ListStyle(), new A.Paragraph( new A.Run( new A.RunProperties() { Language = "en-US", Dirty = false }, new A.Text() { Text = existingSlideNote + "Value Updated" }), new A.EndParagraphRunProperties() { Language = "en-US", Dirty = false })) ))), new ColorMapOverride(new A.MasterColorMapping())); notesSlidePart1.NotesSlide = notesSlide; } } catch (Exception exp) { Console.WriteLine(exp); Console.ReadLine(); } }
private void CreateParts(PresentationDocument document, PresentationGenerationData data) { ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart <ExtendedFilePropertiesPart>("rId3"); GenerateExtendedFilePropertiesPartHelper.GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1); PresentationPart presentationPart1 = document.AddPresentationPart(); GeneratePresentationPartHelper.GeneratePresentationPart1Content(presentationPart1); CommentAuthorsPart commentAuthorsPart1 = presentationPart1.AddNewPart <CommentAuthorsPart>("rId8"); GenerateCommentAuthorsPartHelper.GenerateCommentAuthorsPart1Content(commentAuthorsPart1); CustomXmlPart customXmlPart1 = presentationPart1.AddNewPart <CustomXmlPart>("application/xml", "rId3"); GenerateCustomXmlPartHelper.GenerateCustomXmlPart1Content(customXmlPart1); CustomXmlPropertiesPart customXmlPropertiesPart1 = customXmlPart1.AddNewPart <CustomXmlPropertiesPart>("rId1"); GenerateCustomXmlPropertiesPartHelper.GenerateCustomXmlPropertiesPart1Content(customXmlPropertiesPart1); HandoutMasterPart handoutMasterPart1 = presentationPart1.AddNewPart <HandoutMasterPart>("rId7"); GenerateHandoutMasterPartHelper.GenerateHandoutMasterPart1Content(handoutMasterPart1); ThemePart themePart1 = handoutMasterPart1.AddNewPart <ThemePart>("rId1"); GenerateThemePartHelper.GenerateThemePart1Content(themePart1); TableStylesPart tableStylesPart1 = presentationPart1.AddNewPart <TableStylesPart>("rId12"); GenerateTableStylesPartHelper.GenerateTableStylesPart1Content(tableStylesPart1); CustomXmlPart customXmlPart2 = presentationPart1.AddNewPart <CustomXmlPart>("application/xml", "rId2"); GenerateCustomXmlPartHelper.GenerateCustomXmlPart2Content(customXmlPart2); CustomXmlPropertiesPart customXmlPropertiesPart2 = customXmlPart2.AddNewPart <CustomXmlPropertiesPart>("rId1"); GenerateCustomXmlPropertiesPartHelper.GenerateCustomXmlPropertiesPart2Content(customXmlPropertiesPart2); CustomXmlPart customXmlPart3 = presentationPart1.AddNewPart <CustomXmlPart>("application/xml", "rId1"); GenerateCustomXmlPartHelper.GenerateCustomXmlPart3Content(customXmlPart3); CustomXmlPropertiesPart customXmlPropertiesPart3 = customXmlPart3.AddNewPart <CustomXmlPropertiesPart>("rId1"); GenerateCustomXmlPropertiesPartHelper.GenerateCustomXmlPropertiesPart3Content(customXmlPropertiesPart3); NotesMasterPart notesMasterPart1 = presentationPart1.AddNewPart <NotesMasterPart>("rId6"); GenerateNotesMasterPartHelper.GenerateNotesMasterPart1Content(notesMasterPart1); ThemePart themePart2 = notesMasterPart1.AddNewPart <ThemePart>("rId1"); GenerateThemePartHelper.GenerateThemePart2Content(themePart2); ThemePart themePart3 = presentationPart1.AddNewPart <ThemePart>("rId11"); GenerateThemePartHelper.GenerateThemePart3Content(themePart3); SlidePart slidePart1 = presentationPart1.AddNewPart <SlidePart>("rId5"); GenerateSlidePartHelper.GenerateSlidePart1Content(slidePart1, data); var pictureType = string.Empty; if (!string.IsNullOrEmpty(data.PictureType)) { pictureType = data.PictureType; } else { pictureType = "image/png"; } ImagePart imagePart1 = slidePart1.AddNewPart <ImagePart>(pictureType, "rId3"); GenerateImagePartHelper.GenerateImagePart1Content(imagePart1, data.PictureContent); NotesSlidePart notesSlidePart1 = slidePart1.AddNewPart <NotesSlidePart>("rId2"); GenerateNotesSlidePartHelper.GenerateNotesSlidePart1Content(notesSlidePart1); notesSlidePart1.AddPart(slidePart1, "rId2"); notesSlidePart1.AddPart(notesMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart1Content(slideLayoutPart1); SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart <SlideMasterPart>("rId1"); GenerateSlideMasterPartHelper.GenerateSlideMasterPart1Content(slideMasterPart1); SlideLayoutPart slideLayoutPart2 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId8"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart2Content(slideLayoutPart2); slideLayoutPart2.AddPart(slideMasterPart1, "rId1"); ImagePart imagePart2 = slideMasterPart1.AddNewPart <ImagePart>("image/jpeg", "rId13"); GenerateImagePartHelper.GenerateImagePart2Content(imagePart2); SlideLayoutPart slideLayoutPart3 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId3"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart3Content(slideLayoutPart3); slideLayoutPart3.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart4 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId7"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart4Content(slideLayoutPart4); slideLayoutPart4.AddPart(slideMasterPart1, "rId1"); slideMasterPart1.AddPart(themePart3, "rId12"); slideMasterPart1.AddPart(slideLayoutPart1, "rId2"); SlideLayoutPart slideLayoutPart5 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId1"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart5Content(slideLayoutPart5); ImagePart imagePart3 = slideLayoutPart5.AddNewPart <ImagePart>("image/jpeg", "rId3"); GenerateImagePartHelper.GenerateImagePart3Content(imagePart3); ImagePart imagePart4 = slideLayoutPart5.AddNewPart <ImagePart>("image/png", "rId2"); GenerateImagePartHelper.GenerateImagePart4Content(imagePart4); slideLayoutPart5.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart6 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId6"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart6Content(slideLayoutPart6); slideLayoutPart6.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart7 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId11"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart7Content(slideLayoutPart7); slideLayoutPart7.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart8 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId5"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart8Content(slideLayoutPart8); slideLayoutPart8.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart9 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId10"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart9Content(slideLayoutPart9); slideLayoutPart9.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart10 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId4"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart10Content(slideLayoutPart10); slideLayoutPart10.AddPart(slideMasterPart1, "rId1"); SlideLayoutPart slideLayoutPart11 = slideMasterPart1.AddNewPart <SlideLayoutPart>("rId9"); GenerateSlideLayoutPartHelper.GenerateSlideLayoutPart11Content(slideLayoutPart11); slideLayoutPart11.AddPart(slideMasterPart1, "rId1"); ViewPropertiesPart viewPropertiesPart1 = presentationPart1.AddNewPart <ViewPropertiesPart>("rId10"); GenerateViewPropertiesPartHelper.GenerateViewPropertiesPart1Content(viewPropertiesPart1); presentationPart1.AddPart(slideMasterPart1, "rId4"); PresentationPropertiesPart presentationPropertiesPart1 = presentationPart1.AddNewPart <PresentationPropertiesPart>("rId9"); GeneratePresentationPropertiesPartHelper.GeneratePresentationPropertiesPart1Content(presentationPropertiesPart1); CustomFilePropertiesPart customFilePropertiesPart1 = document.AddNewPart <CustomFilePropertiesPart>("rId4"); CustomFilePropertiesPartHelper.GenerateCustomFilePropertiesPart1Content(customFilePropertiesPart1); SetPackageProperties(document); }