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:
- Create an instance of Presentation class.
- Access the Master Slide collection.
- Try to find existing Layout slides to see if the required one is already available in Layout Slide collection or not.
- Add a new Layout slide if the desired layout is unavailable.
- Add an empty slide with a newly added Layout slide.
- 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); | |
Set Footer Visibility inside Slide
To set footer in a slide using its index position in the slides collection of the presentation, please follow the steps below:
- Create an instance of Presentation class.
- Obtain a slide by its reference index.
- Set Footer visible by making slide footer placeholder visible.
- Set date-time placeholder visible by using SetDateTime method.
- Write the modified presentation file.
Set Child Footer Visibility inside Slide
To set footer and child footer a slide using its index position in the slides collection of the presentation, please follow the steps below:
- Create an instance of Presentation class.
- Obtain the master slide by using its index.
- Set Footer and child footer visibility by making master slide and all child footer placeholder visible.
- Set text to master slide and all child footer placeholder by using SetFooterAndChildFootersText method.
- Set text to master slide and all child date-time placeholder by using SetDateTimeAndChildDateTimesText method.
- Write the modified presentation file.
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); |