Cómo agregar encabezado y pie de página en una presentación

Soporte para código heredado

Para usar el código heredado desarrollado con versiones de Aspose.Slides para Java anteriores a 13.x, necesitas hacer algunos cambios menores en tu código y funcionará como antes. Todas las clases que estaban presentes en el antiguo Aspose.Slides para Java bajo los espacios de nombres Aspose.Slide y Aspose.Slides.Pptx ahora están fusionadas en un solo espacio de nombres Aspose.Slides. Por favor, echa un vistazo al siguiente fragmento de código simple para agregar encabezado y pie de página en una presentación en la API heredada de Aspose.Slides y sigue los pasos que describen cómo migrar a la nueva API fusionada.

Enfoque heredado de Aspose.Slides para Java

PresentationEx sourcePres = new PresentationEx();
//Setting Header Footer visibility properties
sourcePres.setUpdateSlideNumberFields(true);
//Update the Date Time Fields
sourcePres.setUpdateDateTimeFields(true);
//Show date time placeholder
sourcePres.getHeaderFooterManager().isDateTimeVisible(true);
//Show the footer place holder
sourcePres.getHeaderFooterManager().isFooterVisible(true);
//Show Slide Number
sourcePres.getHeaderFooterManager().isSlideNumberVisible(true);
//Set the header footer visibility on Title Slide
sourcePres.getHeaderFooterManager().setVisibilityOnTitleSlide(true);
//Write the presentation to the disk
sourcePres.save("NewSource.pptx",SaveFormat.Pptx);
//Create the presentation
Presentation pres = new Presentation();
//Get first slide
Slide sld = pres.getSlideByPosition(0);
//Access the Header / Footer of the slide
HeaderFooter hf = sld.getHeaderFooter();
//Set Page Number Visibility
hf.setPageNumberVisible(true);
//Set Footer Visibility
hf.setFooterVisible(true);
//Set Header Visibility
hf.setHeaderVisible(true);
//Set Date Time Visibility
hf.setDateTimeVisible(true);
//Set Date Time format
hf.setDateTimeFormat(DateTimeFormat.DateTime_dMMMMyyyy);
//Set Header Text
hf.setHeaderText("Header Text");
//Set Footer Text
hf.setFooterText("Footer Text");
//Write the presentation to the disk
pres.save("HeadFoot.ppt",SaveFormat.Ppt);

Nuevo enfoque de Aspose.Slides para Java 13.x

Presentation sourcePres = new Presentation();
//Setting Header Footer visibility properties
sourcePres.UpdateSlideNumberFields = true;
//Update the Date Time Fields
sourcePres.UpdateDateTimeFields = true;
//Show date time placeholder
sourcePres.HeaderFooterManager.IsDateTimeVisible = true;
//Show the footer place holder
sourcePres.HeaderFooterManager.IsFooterVisible = true;
//Show Slide Number
sourcePres.HeaderFooterManager.IsSlideNumberVisible = true;
//Set the header footer visibility on Title Slide
sourcePres.HeaderFooterManager.SetVisibilityOnTitleSlide(true);
//Write the presentation to the disk
sourcePres.save("NewSource.pptx",SaveFormat.Pptx);