How to turn off update automatically option for Date time in ppt while converting to PDF


#1

Hi,

I was using aspose.slides to convert ppt to pdf. The date&time is updating automatically whenever i am converting to pdf as it selected as update automatically while inserting it. So i would like to turn it off. irrespective of whether it is created in header/footer or inside the content of the data. Can you help how do i do it. I was able to figure it out for word to pdf by setting “field.IsLocked = true;” but not able to figure it out how do we do the same for ppt
Below is the code i use to convert to pdf.

using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(filePath))
{
foreach (ISlide slide in presentation.Slides)
{
if ((slide.Hidden))
{
slide.Hidden = false;
}

                IShapeCollection sc = slide.Shapes;
                int count = sc.Count;
                bool fieldremoveflag = false;

                for (int i = 0; i < count; i++)
                {
                    IShape shape;
                    if (fieldremoveflag)
                    {
                        count = count - 1;
                        i = i - 1;
                        shape = sc[i];
                        fieldremoveflag = false;
                    }
                    else
                    {
                        shape = sc[i];
                    }

                    if (shape.Placeholder != null 
                        && !(shape is Aspose.Slides.PictureFrame)
                        && !(shape is Aspose.Slides.SmartArt.SmartArt))
                    {
                        IPlaceholder pc = ((AutoShape)shape).Placeholder;

                        if (pc != null && pc.Type == PlaceholderType.DateAndTime)
                        {
                          //  sc.Remove(shape);
                            fieldremoveflag = true;
                        }
                        else
                        {
                            if (((AutoShape)shape).TextFrame != null)
                            {
                                foreach (IParagraph para in ((AutoShape)shape).TextFrame.Paragraphs)
                                {
                                    foreach (IPortion port in para.Portions)
                                    {
                                        if (port.Field != null)
                                        {
                                            
                                            if (port.Field.Type.InternalString.Contains("datetime"))
                                            {
                                             //   sc.Remove(shape);
                                                fieldremoveflag = true;
                                               
                                            }
                                        }

                                    }
                                }
                            }
                        }
                    }
                }
            }

            PdfOptions pdfOptions = new PdfOptions();
            pdfOptions.NotesCommentsLayouting.NotesPosition = NotesPositions.BottomTruncated;
            pdfOptions.NotesCommentsLayouting.CommentsPosition = CommentsPositions.Right;

            presentation.Save(destinationPath, Aspose.Slides.Export.SaveFormat.Pdf, pdfOptions);

            return presentation.Slides.Count;
        }

#2

@pradeepdone,

I have observed the sample code shared by you. You are in fact loading a presentation, processing that and then finally saving that to PDF. When you update the contents inside presentation the presentation date time will be updated. If you are somehow able to achieve this in PowerPoint, then please share with us and we will investigate the possibility of implementing the same in Aspose.Slides. I also suggest you to please visit this thread link for your convenience and concept as well.


#3

I have gone through few posts in Aspose and i can see that there was some feature to turn off the auto update Date and time in the ppt by using below condition but looks like this has been removed from latest version of aspose. Can i know the alternative method which does the same thing.

This is available in 16.1.0 version
PresentationEx present = new PresentationEx(path+“2010Presentation2.pptx”);
present.setUpdateDateTimeFields(true);
present.save(path+“2010Presentation2.pptx.pdf”, SaveFormat.Pdf);


#4

@pradeepdone,

I have observed your requirements and like to sahre that the properties UpdateDateTimeFields and UpdateSlideNumberFields are removed since Apose.Slides 16.2.0.

You can find automatically updated date fields with checking IPortion.IField != null and analysing IField.Type using this code snippet:

if (portion.IsField && portion.Field.Type.InternalString.StartsWith("datetime")) { ... }


#5

But in this condition how do i update the time in it. Because as per my requirement i need to find the time which is automatically updating and update that with the last saved time.

IShapeCollection sc = slide.Shapes;
int count = sc.Count;
bool fieldremoveflag = false;

                for (int i = 0; i < count; i++)
                {
                    IShape shape;
                    if (fieldremoveflag)
                    {
                        count = count - 1;
                        i = i - 1;
                        shape = sc[i];
                        fieldremoveflag = false;
                    }
                    else
                    {
                        shape = sc[i];
                    }

                    if (shape.Placeholder != null
                        && !(shape is Aspose.Slides.PictureFrame)
                        && !(shape is Aspose.Slides.SmartArt.SmartArt))
                    {
                        IPlaceholder pc = ((AutoShape)shape).Placeholder;

                     
                            if (((AutoShape)shape).TextFrame != null)
                            {
                                foreach (IParagraph para in ((AutoShape)shape).TextFrame.Paragraphs)
                                {
                                    foreach (IPortion port in para.Portions)
                                    {
                                        if (port.Field != null)
                                        {

                                        if (port.Field.Type.InternalString.StartsWith("datetime"))
                                          //  if (port.Field.Type.InternalString.Contains("datetime"))
                                            {
                                          // Need to update date time here ....

                                            }
                                        }

                                    }
                                }
                            }
                       // }
                    }
                }

#6

@pradeepdone,

I suggest you to please observe the below sample code for your convenience.

static void ReplaceFooterDateTimeExample()
{
    IPresentationInfo info = PresentationFactory.Instance.GetPresentationInfo("pres.pptx");
    IDocumentProperties props = info.ReadDocumentProperties();
    DateTime currentLastSavedTime = props.LastSavedTime.ToLocalTime();

    // Please note that exactly THIS string will be used in resulting PDF document 
    // in date time field. It can be formattd differently in source presentation, 
    // depending on portion.Field.Type.InternalString "datetime" value. If you need to 
    // format this date according to this rules, use this field value.
    string currentLastSavedTimeString = currentLastSavedTime.ToString("G");

    using (Presentation pres = new Presentation("pres.pptx"))
    {
        foreach (ISlide slide in pres.Slides)
        {
            List<AutoShape> shapes = FilterShapes(slide.Shapes);
            SetFooterDateTime(shapes, slide.HeaderFooterManager, currentLastSavedTimeString);
        }

        foreach (ILayoutSlide layoutSlide in pres.LayoutSlides)
        {
            List<AutoShape> layoutShapes = FilterShapes(layoutSlide.Shapes);
            SetFooterDateTime(layoutShapes, layoutSlide.HeaderFooterManager, currentLastSavedTimeString);
        }

        foreach (IMasterSlide masterSlide in pres.Masters)
        {
            List<AutoShape> masterShapes = FilterShapes(masterSlide.Shapes);
            SetFooterDateTime(masterShapes, masterSlide.HeaderFooterManager, currentLastSavedTimeString);
        }

        pres.Save("pres.pdf", SaveFormat.Pdf);
    }
}

static List<AutoShape> FilterShapes(IShapeCollection shapes)
{
    return shapes.OfType<AutoShape>()
            .Where(shape => shape.Placeholder != null && shape.Placeholder.Type == PlaceholderType.DateAndTime)
            .ToList();
}

static void SetFooterDateTime(
    List<AutoShape> lookupForValueShapes, 
    IBaseSlideHeaderFooterManager headerFooterManager,
    string newValue)
{
    string footerDateTimeValue;
    if (TryFindDateTimeFooterValue(lookupForValueShapes, newValue, out footerDateTimeValue))
    {
        headerFooterManager.SetDateTimeText(footerDateTimeValue);
    }
}

static bool TryFindDateTimeFooterValue(IList<AutoShape> shapes, string newValue, out string valueToSet)
{
    valueToSet = null;
    bool result = false;

    foreach (AutoShape shape in shapes)
    {
        IEnumerable<Portion> portions = shape.TextFrame
            .Paragraphs
            .SelectMany(paragraph => paragraph.Portions)
            .Cast<Portion>();

        StringBuilder builder = new StringBuilder();
        foreach (Portion portion in portions)
        {
            if (portion.Field != null && portion.Field.Type.InternalString.StartsWith("datetime"))
            {
                builder.Append(newValue);
                result = true;
            }
            else
            {
                builder.Append(portion.Text);
            }
        }

        if (result)
        {
            valueToSet = builder.ToString();
            return true;
        }
    }

    return false;
}

[.Net] Modifing Handouts header
#7

I have already made some changes which looks almost the same way as you esent. I am able to update the date time in header/footer, Notes and Handouts in ppt. But still not able to figure it out how to update datetime inside the content like center tile or in the main content. Below is my code and source and converted documents.

 using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation("D:\\Convert\\Test.pptx"))
            {
               // presentation.UpdateDateTimeFields = false;
                DateTime lastSavedDateTime = presentation.DocumentProperties.LastSavedTime;
                IPresentationHeaderFooterManager presentationHeaderFooter = presentation.HeaderFooterManager;
                presentationHeaderFooter.SetAllDateTimesVisibility(true);
                presentationHeaderFooter.SetAllDateTimesText(lastSavedDateTime.ToString());
                
                foreach (var notes in presentation.Slides.Select(slide => slide.NotesSlideManager.NotesSlide))
                {
                    if (notes != null)
                    {
                        notes.HeaderFooterManager.SetDateTimeVisibility(true);
                        notes.HeaderFooterManager.SetDateTimeText(lastSavedDateTime.ToString());
                    }
                }

                int slidecount = ((Aspose.Slides.SlideCollection)presentation.Slides).Count;

                for (int i = 0; i < slidecount; i++)
                {
                    IMasterSlideHeaderFooterManager headerFooterManager = presentation.Masters[i].HeaderFooterManager;
                    headerFooterManager.SetDateTimeVisibility(true);
                    headerFooterManager.SetDateTimeAndChildDateTimesText(lastSavedDateTime.ToString());

                    IBaseSlideHeaderFooterManager headerFooterManager1 = presentation.Slides[i].HeaderFooterManager;
                    headerFooterManager1.SetDateTimeVisibility(true);
                    headerFooterManager1.SetDateTimeText(lastSavedDateTime.ToString());
                }
             <a class="attachment" href="/uploads/discourse_instance3/16810">Source.zip</a> (130.7 KB)

                foreach (ISlide slide in presentation.Slides)
                {
                    if ((slide.Hidden))
                    {
                        slide.Hidden = false;
                    }




                    IShapeCollection sc = slide.Shapes;
                    int count = sc.Count;
                   // bool fieldremoveflag = false;

                    for (int i = 0; i < count; i++)
                    {
                        IShape shape;
                        shape = sc[i];
                       

                        if (shape.Placeholder != null
                            && !(shape is Aspose.Slides.PictureFrame)
                            && !(shape is Aspose.Slides.SmartArt.SmartArt))
                        {
                            IPlaceholder pc = ((AutoShape)shape).Placeholder;

                           
                                if (((AutoShape)shape).TextFrame != null)
                                {
                                    foreach (IParagraph para in ((AutoShape)shape).TextFrame.Paragraphs)
                                    {
                                        foreach (IPortion port in para.Portions)
                                        {
                                            if (port.Field != null)
                                            {

                                            if (port.Field.Type.InternalString.StartsWith("datetime"))
                                              //  if (port.Field.Type.InternalString.Contains("datetime"))
                                                {                                                
                                                //  sc.Remove(shape);

                                               // port.Text = lastSavedDateTime.ToString();
                                                fieldremoveflag = true;

                                                }
                                            }

                                        }
                                    }
                                }
                           // }
                        }
                    }
                }



                 PdfOptions pdfOptions = new PdfOptions();
                pdfOptions.DrawSlidesFrame = false;
                pdfOptions.NotesCommentsLayouting.NotesPosition = NotesPositions.BottomTruncated;
                pdfOptions.NotesCommentsLayouting.CommentsPosition = CommentsPositions.Right;

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


            }

#8

@pradeepdone,

Can you please share the source presentation along with generated output that you have generated on your end. I will use the information further on my end and possibly log issue if it gets reproduced on my end.


#9

Please find the source and converted pdf files. In the centered tile i have added two datees one is inserted as automatically update and the other date is inserted manually. I would like to update the first date which updates automatically with last saved date time. Which is not happening with the work around you gave me and even the date in the notes is also not printing.

Source_convertedFiles.zip (138.1 KB)
Note:
Ignore the evaluation version content in pdf as for testing i am running the code separately in a console without updating the license but i do have license for my main application.


#10

Just adding one more point to the above query with the latest licensed version of aspose datetime in the notes are printing but still updating automatically. Can you please look in to this as well along with the above query.


#11

@pradeepdone,

Attached please find the sample project that I have created using sample code provided by you. I have also attached the generated PDF as well for your reference.

ConsoleAspose.zip (607.5 KB)

Date_ppt_Exported.pdf (29.6 KB)

Can you please elaborate this point as by design the dates get updated.


#12

Below are the explanation which are working and which part is failing from the code which i have provided above.
Working Code:
The one which is marked in red colour is working fine as i am replacing the DateTime (which was inserted as update automatically) in header/footer and handouts with last saved time as i don’t to show the updated date time whenever i am converting to pdf.

Failing code:
In the screenshot the one which is highlighted in yellow colour are the dates which are inserted as update automatically in the center tile and notes tile.
so i want to set those dates with last saved datetime as i did for above things but couldn’t able to achieve it through your suggestions.

I hope this is clear and if yes can you please help me out to get this done.pdf.PNG (28.8 KB)


#13

@pradeepdone,

I have observed your comments. An issue with ID SLIDESNET-40366 has been added in our issue tracking system to further investigate and help you out in this matter. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.


#14

Ok thank you.


#15

Any update on this.


#16

@pradeepdone,

I regret to share that the issue specified is not yet resolved because issue is added recently in our issue tracking system. Actually, in Aspose.Slides forum the issues are selected for investigation on first come first serve basis. Also the first priority for scheduling and resolution is given to paid Enterprise and priority support customers. Then Aspose.Slides normal or free support customers issues are scheduled and resolved on first come and first come serve basis. I will share the further information with you as soon as the issue will be resolved.


#17

Hello,

May i please know how much more time it may take for the resolution.


#18

@pradeepdone,

I like to share that the issue has just recently been created in our issue tracking system and is pending for investigation in issues queue. We will share the good news with you as soon as the issue will be fixed.


#19

Hello,

Are you able to find the resolution for the issue i have mentioned.


#20

@pradeepdone,

I have observed your comments. The issue is set for investigation on the next week, after that we will back with solution via snippet or ETA. I request for your patience.