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

Free Support Forum - aspose.com

HeaderFooter

Hi,

I cannot find documentation for HeaderFooter, and I cannot figure out how to use the HeaderFooterManager.

Here is code I need to update from version 8.2:

private static void FixSlideDateTime(
DateTime lastModified,
Aspose.Slides.Slide slide)
{

if (slide.HeaderFooter != null)
{
if (slide.HeaderFooter.IsDateTimeVisible)
{
if (!slide.HeaderFooter.IsDateTimeFixed)
{
//Need to capture existing values before editing
//because if the values are being retrieved from
//the master slide, then a new headerfooter class
//will be created for this slide.
bool isDateTimeVisible = slide.HeaderFooter.IsDateTimeVisible;
bool isFooterVisible = slide.HeaderFooter.IsFooterVisible;
bool isHeaderVisible = slide.HeaderFooter.IsHeaderVisible;
bool isPageNumberVisible = slide.HeaderFooter.IsPageNumberVisible;
string footerText = slide.HeaderFooter.FooterText;
string headerText = slide.HeaderFooter.HeaderText;

slide.HeaderFooter.IsDateTimeFixed = true;
slide.HeaderFooter.DateTimeText = GetPowerPointFormattedDate(
lastModified,
slide.HeaderFooter.DateTimeFormat);

//Now reset the values from the master slide's
//headerfooter.
slide.HeaderFooter.FooterText = footerText;
slide.HeaderFooter.HeaderText = headerText;

if (slide.HeaderFooter.IsDateTimeVisible != isDateTimeVisible)
slide.HeaderFooter.IsDateTimeVisible = isDateTimeVisible;
if (slide.HeaderFooter.IsFooterVisible != isFooterVisible)
slide.HeaderFooter.IsFooterVisible = isFooterVisible;
if (slide.HeaderFooter.IsHeaderVisible != isHeaderVisible)
slide.HeaderFooter.IsHeaderVisible = isHeaderVisible;
if (slide.HeaderFooter.IsPageNumberVisible != isPageNumberVisible)
slide.HeaderFooter.IsPageNumberVisible = isPageNumberVisible;
}
}
}
}

Hi Karen,

I have observed the sample code shared by you and like to share that in new API the header footer are managed on presentation level instead on individual slide level. Please try using the following sample code to serve the purpose on your end. Also, there are no header in new API as well.

private void FixSlideDateTime(DateTime lastModified,Aspose.Slides.Slide slide)
{
IHeaderFooterManager HeaderFooter=slide.Presentation.HeaderFooterManager;

if (HeaderFooter != null)
{
if (HeaderFooter.IsDateTimeVisible)
{
// if (!HeaderFooter.IsDateTimeFixed)
{
//Need to capture existing values before editing
//because if the values are being retrieved from
//the master slide, then a new headerfooter class
//will be created for this slide.
bool isDateTimeVisible = HeaderFooter.IsDateTimeVisible;
bool isFooterVisible = HeaderFooter.IsFooterVisible;
// bool isHeaderVisible = HeaderFooter.IsHeaderVisible;
bool isPageNumberVisible = HeaderFooter.IsSlideNumberVisible;


FieldType fieldType=FieldType.DateTime;

string footerText = AccessHeaderFooter(ref fieldType, PlaceholderType.Footer, slide);
string headerText = AccessHeaderFooter(ref fieldType, PlaceholderType.Header, slide);

// HeaderFooter.IsDateTimeFixed = true;

HeaderFooter.SetDateTimeText= GetPowerPointFormattedDate(
lastModified,
FieldType.DateTime);

//Now reset the values from the master slide’s
//headerfooter.
HeaderFooter.SetFooterText(footerText);
// HeaderFooter.HeaderText = headerText;

if (HeaderFooter.IsDateTimeVisible != isDateTimeVisible)
HeaderFooter.IsDateTimeVisible = isDateTimeVisible;
if (HeaderFooter.IsFooterVisible != isFooterVisible)
HeaderFooter.IsFooterVisible = isFooterVisible;
// if (HeaderFooter.IsHeaderVisible != isHeaderVisible)
// HeaderFooter.IsHeaderVisible = isHeaderVisible;
if (HeaderFooter.IsSlideNumberVisible != isPageNumberVisible)
HeaderFooter.IsSlideNumberVisible = isPageNumberVisible;
}
}
}
}

public String AccessHeaderFooter(ref FieldType fieldtype,PlaceholderType placeholderType,ISlide slide)
{
IMasterSlide master = slide.LayoutSlide.MasterSlide;

foreach (Shape shape in master.Shapes)
{
IPlaceholder place = shape.Placeholder;
if (place != null && (place.Type == PlaceholderType.Footer || place.Type == PlaceholderType.DateAndTime || place.Type == PlaceholderType.SlideNumber))
{
AutoShape ashp = (AutoShape)shape;
ITextFrame text = ashp.TextFrame;

if (placeholderType == place.Type)
{
if (text != null)
{
IPortion port = text.Paragraphs[0].Portions[0];
if (place.Type == PlaceholderType.Footer || place.Type == PlaceholderType.Header)
{
return port.Text;
}
else
{
fieldtype =(FieldType)port.Field.Type ;
}

}

}
}
}
return null;
}

Many Thanks,