Slide Layout

Add Slide Layout to Presentation

Aspose.Slides also offer to add Layout slides in a presentation. There are cases when there is missing Layout slide in the presentation and once can now add the Layout Slides in a presentation. Each slide has unique Id and Layout slides are maintained inside presentation Masters. One can access the Layout slide either by Type or by Name. Aspose.Slides for C++ allows developers to add new Layout slides in the presentation. To add a Layout Slide, please follow the steps below:

  1. Create an instance of Presentation class.
  2. Access the Master Slide collection.
  3. Try to find existing Layout slides to see if the required one is already available in Layout Slide collection or not.
  4. Add a new Layout slide if the desired layout is unavailable.
  5. Add an empty slide with a newly added Layout slide.
  6. Finally, write the presentation file using the Presentation object.

In the example given below, we have added Layout Slides to Presentation.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/AddSlides.pptx";
const String outPath = u"../out/AddLayoutSlides.pptx";
// Instantiate Presentation class that represents the presentation file
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
// Try to search by layout slide type
SharedPtr<IMasterLayoutSlideCollection> layoutSlides = pres->get_Masters()->idx_get(0)->get_LayoutSlides();
SharedPtr<ILayoutSlide> layoutSlide;
if (layoutSlides->GetByType(SlideLayoutType::TitleAndObject) != NULL)
{
layoutSlide = layoutSlides->GetByType(SlideLayoutType::TitleAndObject);
}
else if (layoutSlides->GetByType(SlideLayoutType::Title) != NULL)
{
layoutSlide = layoutSlides->GetByType(SlideLayoutType::Title);
}
if (layoutSlide == NULL)
{
// The situation when a presentation doesn't contain some type of layouts.
// presentation File only contains Blank and Custom layout types.
// But layout slides with Custom types has different slide names,
// like "Title", "Title and Content", etc. And it is possible to use these
// names for layout slide selection.
// Also it is possible to use the set of placeholder shape types. For example,
// Title slide should have only Title pleceholder type, etc.
for (int i = 0; i<layoutSlides->get_Count(); i++)
{
SharedPtr<ILayoutSlide> titleAndObjectLayoutSlide = layoutSlides->idx_get(i);
if (titleAndObjectLayoutSlide->get_Name().Equals(u"Title and Object"))
{
layoutSlide = titleAndObjectLayoutSlide;
break;
}
}
if (layoutSlide == NULL)
{
for (int i = 0; i < layoutSlides->get_Count(); i++)
{
SharedPtr<ILayoutSlide> titleLayoutSlide = layoutSlides->idx_get(i);
if (titleLayoutSlide->get_Name().Equals(u"Title"))
{
layoutSlide = titleLayoutSlide;
break;
}
}
if (layoutSlide == NULL)
{
layoutSlide = layoutSlides->GetByType(SlideLayoutType::Blank);
if (layoutSlide == NULL)
{
layoutSlide = layoutSlides->Add(SlideLayoutType::TitleAndObject, u"Title and Object");
}
}
}
}
// Adding empty slide with added layout slide
pres->get_Slides()->InsertEmptySlide(0, layoutSlide);
// Save the PPTX file to the Disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Set Size and Type of Slide

SlideSize.Type and SlideSize.Size are the properties of presentation class which could be set or get as shown below in the example.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/AddSlides.pptx";
const String outPath = u"../out/CloneToAnotherPresentationWithSetSizeAndType.pptx";
// Instantiate Presentation class
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
//Instantiate target presentation object
SharedPtr<Presentation> destPres = MakeObject<Presentation>();
// Accessing Slide by ID from collection
SharedPtr<ISlideCollection> slideCollection = destPres->get_Slides();
// Set the slide size of generated presentations to that of source
destPres->get_SlideSize()->SetSize(pres->get_SlideSize()->get_Type(), Aspose::Slides::SlideSizeScaleType::DoNotScale);
// destPres->get_SlideSize()->set_Size(Size(pres->get_SlideSize()->get_Type(),);
// Clone the desired slide at desired position of other presentation
slideCollection->InsertClone(1, pres->get_Slides()->idx_get(0));
// Writing the presentation file
destPres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

To set footer in a slide using its index position in the slides collection of the presentation, please follow the steps below:

  1. Create an instance of Presentation class.
  2. Obtain a slide by its reference index.
  3. Set Footer visible by making slide footer placeholder visible.
  4. Set date-time placeholder visible by using SetDateTime method.
  5. Write the modified presentation file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/HeaderFooterManager_out.pptx";
SharedPtr<Presentation> presentation = MakeObject<Presentation>();
// Instantiate SlideCollection calss
SharedPtr<ISlideCollection> slds = presentation->get_Slides();
// SharedPtr<IBaseSlideHeaderFooterManager> headerFooterManager = presentation->get_Slides()->idx_get(0)->get_HeaderFooterManager();
SharedPtr<IMasterSlideHeaderFooterManager> headerFooterManager = presentation->get_Masters()->idx_get(0)->get_HeaderFooterManager();
if (!headerFooterManager->get_IsFooterVisible()) // Property IsFooterVisible is used for indicating that a slide footer placeholder is not present.
{
headerFooterManager->SetFooterVisibility(true); // Method SetFooterVisibility is used for making a slide footer placeholder visible.
}
if (!headerFooterManager->get_IsSlideNumberVisible()) // Property IsSlideNumberVisible is used for indicating that a slide page number placeholder is not present.
{
headerFooterManager->SetSlideNumberVisibility(true); // Method SetSlideNumberVisibility is used for making a slide page number placeholder visible.
}
if (!headerFooterManager->get_IsDateTimeVisible()) // Property IsDateTimeVisible is used for indicating that a slide date-time placeholder is not present.
{
headerFooterManager->SetDateTimeVisibility(true); // Method SetFooterVisibility is used for making a slide date-time placeholder visible.
}
headerFooterManager->SetFooterText(u"Footer text"); // Method SetFooterText is used for setting text to slide footer placeholder.
headerFooterManager->SetDateTimeText(u"Date and time text"); // Method SetDateTimeText is used for setting text to slide date-time placeholder.
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

To set footer and child footer a slide using its index position in the slides collection of the presentation, please follow the steps below:

  1. Create an instance of Presentation class.
  2. Obtain the master slide by using its index.
  3. Set Footer and child footer visibility by making master slide and all child footer placeholder visible.
  4. Set text to master slide and all child footer placeholder by using SetFooterAndChildFootersText method.
  5. Set text to master slide and all child date-time placeholder by using SetDateTimeAndChildDateTimesText method.
  6. Write the modified presentation file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/SetChildFooter_out.pptx";
SharedPtr<Presentation> presentation = MakeObject<Presentation>();
// Instantiate SlideCollection calss
SharedPtr<ISlideCollection> slds = presentation->get_Slides();
SharedPtr<IMasterSlideHeaderFooterManager> headerFooterManager = presentation->get_Masters()->idx_get(0)->get_HeaderFooterManager();
headerFooterManager->SetFooterAndChildFootersVisibility(true); // Method SetFooterAndChildFootersVisibility is used for making a master slide and all child footer placeholders visible.
headerFooterManager->SetSlideNumberAndChildSlideNumbersVisibility(true); // Method SetSlideNumberAndChildSlideNumbersVisibility is used for making a master slide and all child page number placeholders visible.
headerFooterManager->SetDateTimeAndChildDateTimesVisibility(true); // Method SetDateTimeAndChildDateTimesVisibility is used for making a master slide and all child date-time placeholders visible.
headerFooterManager->SetFooterAndChildFootersText(u"Footer text"); // Method SetFooterAndChildFootersText is used for setting text to master slide and all child footer placeholders.
headerFooterManager->SetDateTimeAndChildDateTimesText(u"Date and time text"); // Method SetDateTimeAndChildDateTimesText is used for setting text to master slide and all child date-time placeholders.
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Set Slide Size with Respect to Content Scaling

You can also set the slide size by using it with different ways of content scaling. SlideSize.Type and SlideSize.Size are the properties of presentation class which could be set or get as shown below in the example.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/AccessSlides.pptx";
const String outPath = u"../out/SetSlideSizeScale_out.pptx";
SharedPtr<Presentation> presentation = MakeObject<Presentation>(templatePath);
SharedPtr<Presentation> auxPresentation = MakeObject<Presentation>();
// Instantiate SlideCollection calss
SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0);
// Set the slide size of generated presentations to that of source
auxPresentation->get_SlideSize()->SetSize(540, 720, SlideSizeScaleType::EnsureFit); // Method SetSize is used for set slide size with scale content to ensure fit
auxPresentation->get_SlideSize()->SetSize(SlideSizeType::A4Paper, SlideSizeScaleType::Maximize); // Method SetSize is used for set slide size with maximize size of content
auxPresentation->get_Slides()->InsertClone(0, slide);
auxPresentation->get_Slides()->RemoveAt(0);
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Set Page Size when Generating PDF

Slides in presentation could be set as different paper sizes. The SlideSize.Type property and SlideSizeScaleType enumeration can be used to set the slide size. Developers can set size of slide as shown below in the example.

// The path to the documents directory.
const String outPath = u"../out/SetPDFPageSize_out.pptx";
// Instantiate Presentation class
SharedPtr<Presentation>pres = MakeObject<Presentation>();
// Set SlideSize.Type Property
pres->get_SlideSize()->SetSize(SlideSizeType::A4Paper, SlideSizeScaleType::EnsureFit);
// Set different properties of PDF Options
Aspose::Slides::Export::PdfOptions opts = Aspose::Slides::Export::PdfOptions();
opts.set_SufficientResolution (600);
// Save presentation to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pdf, &opts);