We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Facing issue while comparing two layout of slide

Hi,

I am facing issue while comparing two layout. I am using Apose Slide java version 20.4.

Below zip file have code snippet which I am using to compare the layout.

Assests to investigate.zip (2.2 MB)

In zip there are 3 presentation file:

  1. ThemeFile.pptx which is used to compare the layout with slide.
  2. Slide 1 not matched.pptx whose layout not matched the ThemeFile.pptx.
  3. Slide 2 all layout matched.pptx whose layout matched with theme.

Problem I am facing on Slide 1 not matched.pptx. If I copy and paste the slide from this file to ThemeFile.pptx using powerpoint it add the layout of a slide at the end of ThemeFile. But if I do with aspose code then it is matching with almost all layout except the content layout and generating the presentation with “Divider_01” layout.

Can you please help any kind of code snippet which can be use to compare the structure of layout?

Thanks,
Saquib Shaikh.

@saquibs,

I didn’t quite get the issue/requirement on your end. I have performed the above steps by copying slide manually using PowerPoint and pasting that in Theme file. Attached below observe the image in which I have compared the layout of your 0.pptx and a theme file where slide is manually copied to target. Can you please elaborate the issue that what should be desired behavior and what you are getting.

image.jpg (264.9 KB)

Please also provide the similar details for second presentation as well. If you are looking for option of cloning slide from source to target presentation and applying master slide of target presentation on cloned slide then this addClone() overload is appropriate. When second boolean parameter is set to true then Aspose.Slides automatically adds missing layout slide to target master slide based on layout slide of cloned slide. Otherwise, it will apply the one matching from target master slide.

@mudassir.fayyaz,

I want functionality like powerpoint. while cloning the slide from one file to another powerpoint work as if layout name or layout structure not match with destination layout then it will add the source slide layout to destination layout and then clone the slide.
You can check master structure in below image before pasting the slide and after pasting the slide.
before adding the slide to Theme file.jpg (183.6 KB)
after adding the slide to theme file.jpg (211.1 KB)

But when I have used this solution to compare the layout to check the structure
I have got actual result from Aspose as :
actual result.jpg (62.7 KB)

But expected result should be like :
Expected Result.jpg (175.5 KB)

Even I have used this solution to clone the slide but result I have got like result after cloning.jpg (38.6 KB)

Thanks,
Saquib Shaikh.

@saquibs,

Please try using following example code to achieve the expected result.

    public static void TestCloneIssue()
    {
        String path="C:\\Users\\mudas\\Downloads\\Assests to investigate\\";
        Presentation source= new Presentation(path+"Slide 1 not matched.pptx");
        Presentation target= new Presentation(path+"ThemeFile.pptx");
        ISlideCollection targetSlides=target.getSlides();
   
        ILayoutSlide ClonedLayout=target.getMasters().get_Item(0).getLayoutSlides().addClone(source.getSlides().get_Item(0).getLayoutSlide());
    targetSlides.addClone(source.getSlides().get_Item(0), ClonedLayout); 
	
        target.save(path+"saved.pptx",SaveFormat.Pptx);
    }

saved.zip (468.2 KB)

@mudassir.fayyaz,

Thanks for the support. I guess you have misunderstood the requirement.

I have to compare two layout to check whether both have same structure or not. I have tried this solution but it’s giving unexpected result below mention line of code is not able to compare the layout properly.

themePresentation.getLayoutSlides().get_Item(i).equals(presentation.getSlides().get_Item(0).getLayoutSlide())

Thanks.

@saquibs,

The solution that I have provided generates the desired presentation and LayoutSlide in master as per your desired image. What issue and unexpected results you are having in comparing the LayoutSlide. I suppose you are comparing layout to make decision whether to clone new layout slide to master or use any existing one.

@mudassir.fayyaz,

Yes you get it right, I have to make decision whether to clone new layout or to use existing master layout.

When I did that then I have got output like below image using Aspose Library:
actual result.jpg (62.7 KB)

While doing with the help of below code it is matching the layout with existing layout named as “Divider_01” of ThemeFile.pptx but in actual it does not match with any of the existing layout. Layout of Slide 1 not matched.pptx are different from ThemeFile.pptx .

boolean layoutMatched = false;
	
	// check which layout match with theme file.
	for(int i = 0; i < themePresentation.getLayoutSlides().size(); i++) {
		if(themePresentation.getLayoutSlides().get_Item(i).getName().equals(presentation.getSlides().get_Item(0).getLayoutSlide().getName()) && themePresentation.getLayoutSlides().get_Item(i).equals(presentation.getSlides().get_Item(0).getLayoutSlide())) {
			System.out.println("Layout matched : " +  themePresentation.getLayoutSlides().get_Item(i).equals(presentation.getSlides().get_Item(0).getLayoutSlide()) + " with Layout name : " + themePresentation.getLayoutSlides().get_Item(i).getName());
			themePresentation.getSlides().insertClone(0, presentation.getSlides().get_Item(0), themePresentation.getLayoutSlides().get_Item(i));
			layoutMatched = true;
			break;
		} else {
			System.out.println("Layout not matched : " + themePresentation.getLayoutSlides().get_Item(i).equals(presentation.getSlides().get_Item(0).getLayoutSlide()) + " Layout name : " + themePresentation.getLayoutSlides().get_Item(i).getName());
		}
	}
	// If layout not matched then add layout of a slide to theme presentation then clone the content slide.
	if(!layoutMatched) {
		ILayoutSlide layoutSlide = presentation.getSlides().get_Item(0).getLayoutSlide();
		themePresentation.getMasters().get_Item(0).getLayoutSlides().addClone(layoutSlide);
		
		themePresentation.getSlides().insertClone(0, presentation.getSlides().get_Item(0), themePresentation.getLayoutSlides().get_Item(themePresentation.getLayoutSlides().size() - 1));
		System.out.println("Slide layout added to theme.");
	}

Thanks.

@saquibs,

There seems to be an issue with API while comparing two different layout slides from different master slides in your case. A ticket with ID SLIDESJAVA-38156 has been created to further investigate and resolve the issue and we will share feedback with you as soon as the issue will be addressed.