We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Portion field

Hi,
In this file one.pptx.zip (24.8 KB) you can see textbox i created, then i added Date and Time( i didn’t select update automatically option). Is there a way to get field from this portion or get confirmation that this portion is a Date and Time.
Here is my code:

Presentation presentation = new Presentation("one.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
IShapeCollection shapes = slide.getShapes();
AutoShape shape = (AutoShape) shapes.get_Item(0);
IParagraphCollection paragraphs = shape.getTextFrame().getParagraphs();
IPortionCollection portions = paragraphs.get_Item(0).getPortions();
IPortion portion = portions.get_Item(0);
IField field = portion.getField();
System.out.println(field==null); // this prints true

Thanks,
Zeljko.

@Zeljko,

I have observed your comments. I have shared code snippet with you. This will help you to achieve requirements. You have to access Placeholder with DateAndTime type. Please share feedback with us if there is still an issue.

Presentation pres = new Presentation(“one.pptx”);
IShapeCollection sc = pres.getSlides().get_Item(0).getShapes();
for(int i=0;i<sc.size();i++)
{
IShape shape = sc.get_Item(i);
IPlaceholder pc = ((AutoShape)shape).getPlaceholder();
if(pc != null && pc.getType() == PlaceholderType.DateAndTime)
{
System.out.println(((AutoShape)shape).getTextFrame().getText());
}
}

I have used the same code but DateTime field is not detecting and it is not removing while saving it to pdf. Please see the below code. This PlaceholderType.DateAndTime is used to get the Automatic updated date time inside the file right.

using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(“D:\Convert\1.pptx”))
{

            foreach (ISlide slide in presentation.Slides)
            {

                IShapeCollection sc = slide.Shapes;
       
                for (int i = 0; i < sc.Count; i++)
                {
                    IShape shape = sc[i];
                    if (shape.Placeholder != null)
                    {
                        IPlaceholder pc = ((AutoShape)shape).Placeholder;
                      
                        //if (pc != null && pc.GetType() == PlaceholderType.DateAndTime)
                        if (pc != null && pc.Type == PlaceholderType.DateAndTime)
                        {
                            Console.WriteLine(((AutoShape)shape).TextFrame.Text);
                            sc.Remove(shape);
                        }
                    }
                }
            }

            presentation.Save("D:\\Convert\\PPT.pdf", Aspose.Slides.Export.SaveFormat.Pdf);

        }

@pradeepdone,

I have observed that you have requested similar inquiry in another forum thread as well. I suggest you to please visit following link for your reference.