How to Add a Placeholder to Shape in a PowerPoint Presentation in Java?

I can’t add placeholder to shape. The constructor of class Placeholder is not public
88265708590a8404d0c6d53966968ab.png (6.3 KB)

@iyyb930,
Thank you for your inquiry.

I’ve performed some research. It looks like only an existing placeholder can be added to a shape.

Documents: Manage Placeholder
API Reference: IShape Interface

Could you please describe in more detail what you want to achieve? It helps us to understand your requirements and assist you.

@Andrey_Potapov I serialized the ppt with placeholders into a jason file to facilitate the use of database storage management, but when restoring jason to ppt, I need to restore the placeholder in the saved file

@iyyb930,
Where is the shape placed (Slide, Slide Layout, Slide Master)? It would be great if you could share a sample presentation.

This is a sample pres. I will get all the attributes, such as the four basic attributes of the placeholder, and save them in jason. When I want to use them, I use the api to restore the jason to a slide, and now I restore it I don’t know how to restore it when there is a placeholder in the slide. I understand that it is to restore the placeholder in the layout, and then apply the layout to the slide. I don’t know how to implement it.
p1.zip (23.6 KB)

@iyyb930,
Thank you for the additional information. I’ve added a ticket with ID SLIDESJAVA-38685 in our issue tracking system. Our development team will consider such an ability to restore placeholders using Aspose.Slides. You will be notified when the issue is resolved.

@iyyb930,
Our development team investigated the issue. Unfortunately, you cannot create Placeholder instances. You have to save and restore the slide layout, which will retain all of its placeholders. By default, the presentation already has all the standard slide layouts (you also can create a new layout). The following code example shows you how to do this:

Presentation pres = new Presentation();
try {
    //Remove the default slide
    pres.getSlides().get_Item(0).remove();
    //Select the desired slide layout
    ILayoutSlide layoutSlide = pres.getMasters().get_Item(0).getLayoutSlides().get_Item(0);
    //or create a new slide layout 
    ILayoutSlide newLayoutSlide = pres.getMasters().get_Item(0).getLayoutSlides().add(SlideLayoutType.TwoObjects, "Two Object Layout");

    //Create a new slide with the selected slide layout
    pres.getSlides().addEmptySlide(layoutSlide);
    pres.getSlides().addEmptySlide(newLayoutSlide);

    pres.save("output.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

Documents: Slide Layout
API Reference: ISlideCollection Interface