Hi Team,
We are planning to buy this product for our organization. So currently I am testing your product with temporary license for this product.
We are using this product to merge different PPT files into single file.
For that I create one Master default slide which have page number. So while we merge different ppt we have unique number on each slide which we want.
But, main issue is if any of our selection ppt file using any type of master inside that than it will cause an issue while we merge with our new ppt file. Mainly we loss all formatting while clone source slide to destination.
So we want page number in new merge file and want to keep same source formatting to destination slide. So, need solution for that as soon as possible.
Please see attachment files for that with issue sample file and test file along with master file.
MergePPTIssueWith Master.zip (973.2 KB)
Thanks,
Arti Mavani
@artimavani
Thank you for contacting support. We will investigate your issue and report the results.
@artimavani
Thank you for your patience.
In general, your task can be solved using our library.
Please look at the result: out_master.zip (816.7 KB)
Source:
public static void Main()
{
string dataDir = @".\MergePPTIssueWith Master\";
string[] filePaths = Directory.GetFiles(dataDir + "inputFiles");
using (Presentation dest = new Presentation(dataDir + "Master Slide\\MasterPage2.pptx"))
{
IMasterSlide masterSlide = dest.Masters[0];
foreach (string pptxFile in filePaths)
{
if (File.Exists(pptxFile))
{
using (Presentation source = new Presentation(pptxFile))
{
RemoveSlideNumbers(source);
foreach (ISlide eachSlide in source.Slides)
{
ISlide slide = dest.Slides.AddClone(eachSlide);
foreach (IShape shape in masterSlide.Shapes)
{
slide.Shapes.AddClone(shape);
}
}
}
}
}
dest.Save(dataDir + "out_master.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
}
static void RemoveSlideNumbers(Presentation pres)
{
foreach (IMasterSlide master in pres.Masters)
{
var toRemoves = new List<IShape>();
foreach (IShape masterShape in master.Shapes)
{
if (masterShape.Placeholder != null && masterShape.Placeholder.Type == PlaceholderType.SlideNumber)
{
toRemoves.Add(masterShape);
}
AutoShape autoShape = masterShape as AutoShape;
if (autoShape != null)
{
foreach (IParagraph paragraph in autoShape.TextFrame.Paragraphs)
{
var fieldToRemoves = new List<IPortion>();
foreach (IPortion portion in paragraph.Portions)
{
if (portion.Field != null && portion.Field.Type.InternalString == "slidenum")
{
fieldToRemoves.Add(portion);
}
}
foreach (IPortion toRemove in fieldToRemoves)
{
paragraph.Portions.Remove(toRemove);
}
}
}
}
foreach (IShape toRemove in toRemoves)
{
master.Shapes.Remove(toRemove);
}
}
}