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); }