ShapeCrawler
ShapeCrawler copied to clipboard
Proportions are not respected when the slide is copied
📄Description
Slides.Add() does not keep the image proportions when copying a slide to another presentation that has a different slide size.
🚶Steps to Reproduce:
- Run the following code:
var sourcePres = new Presentation("source.pptx");
var targetPres = new Presentation("target.pptx");
var addingSlide = sourcePres.Slides.First();
targetPres.Slides.Add(addingSlide);
targetPres.SaveAs("actual-result.pptx");
Expected Result: The proportions of the picture should be preserved as it occurs when copying a slide using PowerPoint:
Actual Result: The proportions of the picture is not preserved.
actual-result.pptx:
Environment: Library v0.54.1
Initial Message
using var source = SCPresentation.Open(sourcePath);
using var target = SCPresentation.Open(filePath);
var copyingSlide = source.Slides[0];
target.Slides.Add(copyingSlide);
target.Save();
target.Close();
source.Close();
then I get:
The original slide looks like this:
Problem solved.
My target is a newly created .pptx file with a default ratio of 4:3, although I changed it to 16:9 in Microsoft PowerPoint, and a newly created slide in PowerPoint is 16:9. It looks like it's still affected by the 4:3 when copying the slide using the openxml sdk.
I made a copy of the source file, deleted all the pages, re-executed the code, and everything worked fine!
But I still don't know why it works when I copy over a file, is it possible that the information about the page scale is stored in a different place in the target and source files?
The real reason for the problem is:
The canvas size is different from one .pptx file to another, and has nothing to do with whether the page ratio is 16:9 or 4:3.
Copying a slide directly using ShapeCrawler will be the original size of all the shapes, as shown in the image below, where I used ShapeCrawler to take a slide from a larger size canvas, and copy it to a smaller size canvas, it will not show the full area.
When copying a slide using Microsoft Powerpoint, it automatically resizes all the shapes in equal proportions to the new .pptx file.
It seems that to realize the ability to copy slides in multiple .pptx files, you have to take into account the different canvas sizes of the different .pptx files.
I'm trying to work around this using the openxml sdk, I'm copying all the shapes into new files, but it seems to have some compatibility issues just like shapeCrawler,
It looks like to implement the slide copy function for different .pptx files, you either need to make sure the canvas size is the same, or you need to get the size of the canvas first, and then scale all the shapes equally!
@LeonLiu2020, thank you for the issue report.
Yes, it is a bug. The current slide-copying implementation doesn't consider the case when the source and target presentations have different slide sizes.
It needs to be fixed.