Beispiel #1
0
        internal static void AppendSlideMaster(PresentationPart presentationPart, SlideMaster slideMaster, IEnumerable <SlideLayout> slideLayouts)
        {
            // append a new SlideMasterPart
            SlideMasterPart slideMasterPart = presentationPart.AddNewPartDefaultId <SlideMasterPart>();

            // clear SlideLayoutIdList and rebuild it
            slideMaster.SlideLayoutIdList = new SlideLayoutIdList();

            foreach (SlideLayout slideLayout in slideLayouts)
            {
                SlideLayoutPart slideLayoutPart = slideMasterPart.AddNewPartDefaultId <SlideLayoutPart>(out string slideLayoutPartId);
                slideLayoutPart.CreateRelationshipToPartDefaultId(slideMasterPart);
                slideLayout.Save(slideLayoutPart);

                // add to SlideLayoutIdList
                slideMaster.SlideLayoutIdList.AppendChild(new SlideLayoutId()
                {
                    Id             = slideMaster.SlideLayoutIdList.Elements <SlideLayoutId>().Select(sl => sl.Id.Value).DefaultIfEmpty(2147483648u).Max() + 1,
                    RelationshipId = slideMasterPart.GetIdOfPart(slideLayoutPart)
                });
            }

            slideMasterPart.CreateRelationshipToPartDefaultId(presentationPart.ThemePart);
            slideMaster.Save(slideMasterPart);

            AddSlideMasterToSlideMasterIdList(presentationPart, slideMasterPart);
        }
        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);
        }