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

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 ....

                                            }
                                        }

                                    }
                                }
                            }
                       // }
                    }
                }

@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;
}

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/default/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);                


            }

@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.

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.

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.

@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.

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)

@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.

Ok thank you.

Any update on this.

@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.

Hello,

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

@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.

Hello,

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

@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.

Ok thank you. Please update me once it is done.

@pradeepdone,

I suggest you to please try using following sample code on your end and share if there is any issue incurring.

public static void TestDateIssueinPDF()
{
	String path = @"C:\Aspose Data\Source_convertedFiles\";

	using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(path + "Test.pptx"))
	{
		DateTime lastSavedDateTime = presentation.DocumentProperties.LastSavedTime;

		// Set "lastSavedDateTime" to all DateTime placeholders in presentation
		IPresentationHeaderFooterManager presentationHeaderFooter = presentation.HeaderFooterManager;
		presentationHeaderFooter.SetAllDateTimesVisibility(true);
		presentationHeaderFooter.SetAllDateTimesText(lastSavedDateTime.ToString());

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

			// Set "lastSavedDateTime" to slides internal DateTime portions
			SetDateTimeText(slide, lastSavedDateTime.ToString());

			if (slide.NotesSlideManager.NotesSlide != null)
			{
				// Set "lastSavedDateTime" to notes internal DateTime portions
				SetDateTimeText(slide.NotesSlideManager.NotesSlide, lastSavedDateTime.ToString());
			}
		}

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

		presentation.Save(path + "Date_ppt_Exported.pdf", Aspose.Slides.Export.SaveFormat.Pdf, pdfOptions);
	}
}

private static void SetDateTimeText(IBaseSlide baseSlide, string text)
{
	foreach (IShape shape in baseSlide.Shapes)
	{
		if (shape is Aspose.Slides.AutoShape && ((AutoShape)shape).TextFrame != null)
		{
			foreach (IParagraph para in ((AutoShape)shape).TextFrame.Paragraphs)
			{
				foreach (IPortion port in para.Portions)
				{
					if (port.Field != null && port.Field.Type.InternalString.StartsWith("datetime"))
					{
						port.RemoveField();
						port.Text = text;
					}
				}
			}
		}
	}
}

Thank you it’s working now as expected.

The issues you have found earlier (filed as SLIDESNET-40366) have been fixed in this update.