public void AddVideo(SlidePart slidepart, string videoFilePath, string videoCoverPath, D.Transform2D transform) { Slide slide = slidepart.Slide; ShapeTree shapeTree1 = slidepart.Slide.CommonSlideData.ShapeTree; var ptrlid = Doc.PresentationPart.GetIdOfPart(slidepart); var picID = AnalysisHelper.GetMaxId(shapeTree1); string imgEmbedId = string.Format("imgId{0}{1}{2}", ptrlid, picID, 1); string videoEmbedId = string.Format("vidId{0}{1}{2}", ptrlid, picID, 2); string mediaEmbedId = string.Format("medId{0}{1}{2}", ptrlid, picID, 3); Picture picture1 = new Picture(); NonVisualPictureProperties nonVisualPictureProperties1 = new NonVisualPictureProperties(); NonVisualDrawingProperties nonVisualDrawingProperties2 = new NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = videoEmbedId + "" }; D.HyperlinkOnClick hyperlinkOnClick1 = new D.HyperlinkOnClick() { Id = "", Action = "ppaction://media" }; nonVisualDrawingProperties2.Append(hyperlinkOnClick1); NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties(); D.PictureLocks pictureLocks1 = new D.PictureLocks() { NoChangeAspect = true }; nonVisualPictureDrawingProperties1.Append(pictureLocks1); ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties2 = new ApplicationNonVisualDrawingProperties(); D.VideoFromFile videoFromFile1 = new D.VideoFromFile() { Link = videoEmbedId }; ApplicationNonVisualDrawingPropertiesExtensionList applicationNonVisualDrawingPropertiesExtensionList1 = new ApplicationNonVisualDrawingPropertiesExtensionList(); ApplicationNonVisualDrawingPropertiesExtension applicationNonVisualDrawingPropertiesExtension1 = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}" }; P14.Media media1 = new P14.Media() { Embed = mediaEmbedId }; media1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); applicationNonVisualDrawingPropertiesExtension1.Append(media1); applicationNonVisualDrawingPropertiesExtensionList1.Append(applicationNonVisualDrawingPropertiesExtension1); applicationNonVisualDrawingProperties2.Append(videoFromFile1); applicationNonVisualDrawingProperties2.Append(applicationNonVisualDrawingPropertiesExtensionList1); nonVisualPictureProperties1.Append(nonVisualDrawingProperties2); nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1); nonVisualPictureProperties1.Append(applicationNonVisualDrawingProperties2); BlipFill blipFill1 = new BlipFill(); D.Blip blip1 = new D.Blip() { Embed = imgEmbedId }; D.Stretch stretch1 = new D.Stretch(); D.FillRectangle fillRectangle1 = new D.FillRectangle(); stretch1.Append(fillRectangle1); blipFill1.Append(blip1); blipFill1.Append(stretch1); ShapeProperties shapeProperties1 = new ShapeProperties(); D.PresetGeometry presetGeometry1 = new D.PresetGeometry() { Preset = D.ShapeTypeValues.Rectangle }; D.AdjustValueList adjustValueList1 = new D.AdjustValueList(); presetGeometry1.Append(adjustValueList1); shapeProperties1.Append(transform); shapeProperties1.Append(presetGeometry1); picture1.Append(nonVisualPictureProperties1); picture1.Append(blipFill1); picture1.Append(shapeProperties1); shapeTree1.Append(picture1); if (!(slide.Timing?.ChildElements?.Count > 0)) { AnalysisHelper.InitTiming(slide); } ImagePart imagePart = slidepart.AddImagePart(AnalysisHelper.GetImagePartType(videoCoverPath), imgEmbedId); using (var data = File.OpenRead(videoCoverPath)) { imagePart.FeedData(data); }; Doc.PartExtensionProvider.AddPartExtension("video/mp4", ".mp4"); MediaDataPart mediaDataPart1 = Doc.CreateMediaDataPart("video/mp4", ".mp4"); using (System.IO.Stream mediaDataPart1Stream = File.OpenRead(videoFilePath)) { mediaDataPart1.FeedData(mediaDataPart1Stream); } slidepart.AddVideoReferenceRelationship(mediaDataPart1, videoEmbedId); slidepart.AddMediaReferenceRelationship(mediaDataPart1, mediaEmbedId); slide.Save(); }
public void AddImageContent(ShapeTree shapeTree1, uint ObjectID, PPTXImage Content) { Picture picture3 = new Picture(); NonVisualPictureProperties nonVisualPictureProperties3 = new NonVisualPictureProperties(); NonVisualDrawingProperties nonVisualDrawingProperties83 = new NonVisualDrawingProperties() { Id = ObjectID, Name = $"Content{ObjectID}" }; A.NonVisualDrawingPropertiesExtensionList nonVisualDrawingPropertiesExtensionList5 = new A.NonVisualDrawingPropertiesExtensionList(); nonVisualDrawingProperties83.Append(nonVisualDrawingPropertiesExtensionList5); NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties3 = new NonVisualPictureDrawingProperties(); A.PictureLocks pictureLocks3 = new A.PictureLocks() { NoChangeAspect = true }; nonVisualPictureDrawingProperties3.Append(pictureLocks3); ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties83 = new ApplicationNonVisualDrawingProperties(); nonVisualPictureProperties3.Append(nonVisualDrawingProperties83); nonVisualPictureProperties3.Append(nonVisualPictureDrawingProperties3); nonVisualPictureProperties3.Append(applicationNonVisualDrawingProperties83); BlipFill blipFill3 = new BlipFill(); A.Blip blip3 = new A.Blip() { Embed = ImageIDMap[Content.ImageFilePath] }; A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList(); blip3.Append(blipExtensionList1); A.Stretch stretch3 = new A.Stretch(); A.FillRectangle fillRectangle3 = new A.FillRectangle(); stretch3.Append(fillRectangle3); blipFill3.Append(blip3); blipFill3.Append(stretch3); ShapeProperties shapeProperties70 = new ShapeProperties(); A.PresetGeometry presetGeometry10 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle }; A.AdjustValueList adjustValueList10 = new A.AdjustValueList(); presetGeometry10.Append(adjustValueList10); A.Transform2D transform2D25 = SlideWriterHelper.CreateTransform2D(Content.Transform); if (transform2D25 != null) { shapeProperties70.Append(transform2D25); } shapeProperties70.Append(presetGeometry10); picture3.Append(nonVisualPictureProperties3); picture3.Append(blipFill3); picture3.Append(shapeProperties70); shapeTree1.Append(picture3); }