wordpress hit counter
Problem while creating multiple slides using sdk - .Net - Development Tools - OpenXML Developer

Problem while creating multiple slides using sdk

Development Tools

Discussions about working with Open XML using a wide range of development tools

Problem while creating multiple slides using sdk

  • rated by 0 users
  • This post has 4 Replies |
  • 4 Followers
  • Hi everyone,
    When I am creating 1 slide no problem..
    But, when I am trying to create more than 1 slide, then problem is coming..
    Data is coming properly, But while opening ppt file It is asking for Repair...When I say repair then data is properly coming. 
    But when 1 slide is there then it is opening perfectly without any repair..
    Plase help me out....
    Thanks in advance...
    My code is....

    public PresentationPart CreatePages(PresentationPart presentationPart1, ArrayList alPages)
    {
    int iTotalSlides = alPages.Count;
    GeneratePresentationPart1Content(presentationPart1, iTotalSlides);
    SlidePart slidePart1 = presentationPart1.AddNewPart<SlidePart>();
    for (int i = 0; i < alPages.Count; i++)
    {
    slidePart1 = presentationPart1.AddNewPart<SlidePart>("rIdslidePart"+(i+1));
    AddNewPage(i+1, slidePart1);
    }
    SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart<SlideLayoutPart>("rIdslideLayoutPart1");
    GenerateSlideLayoutPart1Content(slideLayoutPart1);
    slidePart1.AddPart(slideLayoutPart1);
    
    SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart<SlideMasterPart>("rIdslideMasterPart1");
    GenerateSlideMasterPart1Content(slideMasterPart1);
    slideMasterPart1.AddPart(slideLayoutPart1, "rId1");
    
    presentationPart1.AddPart(slideMasterPart1, "rId1");
    ThemePart themePart1 = slideMasterPart1.AddNewPart<ThemePart>("rIdthemMaster12");
    GenerateThemePart1Content(themePart1);
    presentationPart1.AddPart(themePart1, "rIdtheme5");
    return presentationPart1;
    }
    
    public void AddNewPage(List<PageBO> lstPageDetails, int iPageNum,SlidePart slidePart1)
    {
    Slide slide1 = new Slide();
    slide1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
    slide1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    slide1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");
    CommonSlideData commonSlideData1 = new CommonSlideData();
    ShapeTree shapeTree1 = new ShapeTree();
    .........
    }
    
    private void GeneratePresentationPart1Content(PresentationPart presentationPart1, int iTotalSlides)
    {
    	Presentation presentation1 = new Presentation() { SaveSubsetFonts = true };
    	presentation1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
    	presentation1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    	presentation1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");
    
    	SlideMasterIdList slideMasterIdList1 = new SlideMasterIdList();
    
    	SlideIdList slideIdList1 = new SlideIdList();
    	for (int i = 0; i < iTotalSlides; i++)
    	{
    		SlideId slideId1 = new SlideId();
    		slideId1.RelationshipId = "rIdslidePart" + (i + 1);
    		slideId1.Id = Convert.ToUInt32(i + 256);
    		slideIdList1.Append(slideId1);
    
    		SlideMasterId slideMasterId1 = new SlideMasterId() { Id = Convert.ToUInt32(i + 2147483648), RelationshipId = "rId"+(i+1) };
    		slideMasterIdList1.Append(slideMasterId1); 
    	}
    	.........
    }
    
    // Generates content of slideMasterPart1.
    private void GenerateSlideMasterPart1Content(SlideMasterPart slideMasterPart1)
    {
    	SlideMaster slideMaster = new SlideMaster(
    	new CommonSlideData(new ShapeTree(
    	  new P.NonVisualGroupShapeProperties(
    	  new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
    	  new P.NonVisualGroupShapeDrawingProperties(),
    	  new ApplicationNonVisualDrawingProperties()),
    	  new GroupShapeProperties(new DocumentFormat.OpenXml.Drawing.TransformGroup()),
    	  new P.Shape(
    	  new P.NonVisualShapeProperties(
    		new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title" },
    		new P.NonVisualShapeDrawingProperties(new DocumentFormat.OpenXml.Drawing.ShapeLocks() { NoGrouping = true }),
    		new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Title })),
    	  new P.ShapeProperties(),
    	  new P.TextBody(
    		new DocumentFormat.OpenXml.Drawing.BodyProperties(),
    		new DocumentFormat.OpenXml.Drawing.ListStyle(),
    		new DocumentFormat.OpenXml.Drawing.Paragraph())))),
    	new P.ColorMap() { Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink },
    	new SlideLayoutIdList(new SlideLayoutId() { Id = (UInt32Value)2147483649U, RelationshipId = "rId1" }),
    	new TextStyles(new TitleStyle(), new BodyStyle(), new OtherStyle()));
    
    	slideMasterPart1.SlideMaster = slideMaster;
    }
    // Generates content of themePart1.
    private void GenerateThemePart1Content(ThemePart themePart1)
    {
    	.......
    }
    
    // Generates content of slideLayoutPart1.
    private void GenerateSlideLayoutPart1Content(SlideLayoutPart slideLayoutPart1)
    {
    	SlideLayout slideLayout1 = new SlideLayout() { Type = SlideLayoutValues.Object, Preserve = true };
    	slideLayout1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
    	slideLayout1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    	slideLayout1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");
    	....
    }

  • If it works after the repair, I would suggest saving a copy of the repaired version, then compare the original with the repaired version. The Open XML SDK 2.0 Productivity Tool is great for comparing documents.

  • You don't list all the code for the AddNewPage routine. I'd venture a guess that it is in there. BTW, do you "save" the slide after creating it?

  • Hi,
        Look at the master reference Id's
      While adding master page to PresentationPart, you have used "rIdSlideMasterPart1" (marked right side), and while adding each slide you are using ' "rId":+(i+1) '.

    Please refer this thread. I have given an example how to add multiple slides. To add slides in specific position refer this thread.  Hope you get the answer there.

  • Thank u all for your response.

    Now everything is working fine.

Page 1 of 1 (5 items)