Gérer le zoom de présentation en Python via Java
Introduction
Les zooms PowerPoint vous permettent de naviguer entre des diapositives et des sections spécifiques pendant un diaporama. Avec Aspose.Slides for Python via Java, vous pouvez créer des zooms de diapositive, de section et de résumé et personnaliser leurs aperçus, bordures et transitions.

- Pour résumer toute une présentation sur une seule diapositive, utilisez un Summary Zoom.
- Pour n’afficher que les diapositives sélectionnées, utilisez un Slide Zoom.
- Pour n’afficher qu’une seule section, utilisez un Section Zoom.
Zoom de diapositive
Un zoom de diapositive peut rendre votre présentation plus dynamique, en vous permettant de naviguer librement entre les diapositives dans l’ordre de votre choix sans interrompre le flux de votre présentation. Les zooms de diapositive sont excellents pour les présentations courtes sans beaucoup de sections, mais vous pouvez également les utiliser dans différents scénarios de présentation.
Les zooms de diapositive vous permettent d’explorer des informations liées à partir d’une diapositive d’aperçu unique.

Pour les objets de zoom de diapositive, Aspose.Slides fournit l’énumération ZoomImageType, la classe ZoomFrame et les méthodes de la classe ShapeCollection.
Créer des cadres de zoom
Utilisez ShapeCollection.addZoomFrame pour placer des liens vers des diapositives individuelles sur une diapositive d’aperçu. Cet exemple crée deux diapositives cibles avec des arrière-plans et des libellés distincts, puis ajoute un aperçu de chacune à la première diapositive et enregistre la présentation au format PPTX. Les positions et dimensions des cadres sont spécifiées en points.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
second_slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
third_slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
second_slide.getBackground().setType(BackgroundType.OwnBackground)
second_slide.getBackground().getFillFormat().setFillType(FillType.Solid)
second_slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color.CYAN)
text_box = second_slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 500, 200)
text_box.getTextFrame().setText("Second Slide")
third_slide.getBackground().setType(BackgroundType.OwnBackground)
third_slide.getBackground().getFillFormat().setFillType(FillType.Solid)
third_slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(189, 183, 107))
text_box = third_slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 500, 200)
text_box.getTextFrame().setText("Third Slide")
overview_slide.getShapes().addZoomFrame(20, 20, 250, 200, second_slide)
overview_slide.getShapes().addZoomFrame(200, 250, 250, 200, third_slide)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Créer des cadres de zoom avec des images personnalisées
Passez une image personnalisée à ShapeCollection.addZoomFrame pour remplacer l’aperçu par défaut de la diapositive cible. Cet exemple nécessite une image locale, la charge avec Images.fromFile, et l’ajoute à la présentation en utilisant ImageCollection.addImage. Le cadre résultant affiche cette image tout en conservant le lien vers la deuxième diapositive.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Images, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().setType(BackgroundType.OwnBackground)
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color.CYAN)
text_box = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 500, 200)
text_box.getTextFrame().setText("Second Slide")
image = Images.fromFile("image.png")
try:
preview_image = presentation.getImages().addImage(image)
finally:
image.dispose()
overview_slide.getShapes().addZoomFrame(20, 20, 300, 200, slide, preview_image)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Mettre en forme les cadres de zoom
Cet exemple personnalise deux cadres de zoom de diapositive. Il attribue une image locale au premier cadre via ZoomObject.setZoomImage, et donne au deuxième cadre une bordure rose pointillée de cinq points grâce à Shape.getLineFormat. Passer False à ZoomObject.setShowBackground masque l’arrière-plan du deuxième cadre. Une image locale est requise pour l’aperçu personnalisé ; les deux cadres conservent leurs cibles de diapositive dans le PPTX enregistré.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Images, LineDashStyle, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
second_slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
third_slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
second_slide.getBackground().setType(BackgroundType.OwnBackground)
second_slide.getBackground().getFillFormat().setFillType(FillType.Solid)
second_slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color.CYAN)
text_box = second_slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 500, 200)
text_box.getTextFrame().setText("Second Slide")
third_slide.getBackground().setType(BackgroundType.OwnBackground)
third_slide.getBackground().getFillFormat().setFillType(FillType.Solid)
third_slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(189, 183, 107))
text_box = third_slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 500, 200)
text_box.getTextFrame().setText("Third Slide")
first_zoom_frame = overview_slide.getShapes().addZoomFrame(20, 20, 250, 200, second_slide)
second_zoom_frame = overview_slide.getShapes().addZoomFrame(200, 250, 250, 200, third_slide)
image = Images.fromFile("image.png")
try:
preview_image = presentation.getImages().addImage(image)
finally:
image.dispose()
first_zoom_frame.setZoomImage(preview_image)
second_zoom_frame.getLineFormat().setWidth(5)
second_zoom_frame.getLineFormat().getFillFormat().setFillType(FillType.Solid)
second_zoom_frame.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color(255, 105, 180))
second_zoom_frame.getLineFormat().setDashStyle(LineDashStyle.DashDot)
second_zoom_frame.setShowBackground(False)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Zoom de section
Un zoom de section crée un lien vers une section de votre présentation. Utilisez-le pour revisiter un sujet ou montrer comment différentes parties de la présentation sont reliées.

Pour les objets de zoom de section, Aspose.Slides fournit la classe SectionZoomFrame ainsi que les méthodes de la classe ShapeCollection.
Créer des cadres de zoom de section
Créez une section avec SectionCollection.addSection, puis transmettez la section renvoyée à ShapeCollection.addSectionZoomFrame. Cet exemple place un zoom de section sur la première diapositive et le lie à une section commençant par une diapositive colorée. La position et les dimensions du cadre sont spécifiées en points, et la présentation est enregistrée au format PPTX.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Presentation, SaveFormat
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(154, 205, 50))
slide.getBackground().setType(BackgroundType.OwnBackground)
section = presentation.getSections().addSection("Section 1", slide)
section_zoom_frame = overview_slide.getShapes().addSectionZoomFrame(20, 20, 300, 200, section)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Créer des cadres de zoom de section avec des images personnalisées
La surcharge d’image de ShapeCollection.addSectionZoomFrame vous permet d’afficher un aperçu personnalisé sans modifier la section de destination. Cet exemple nécessite une image locale, qui est chargée avec Images.fromFile et ajoutée via ImageCollection.addImage. La présentation enregistrée contient un zoom de section sur la première diapositive lié à la section nouvellement créée.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Images, Presentation, SaveFormat
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(154, 205, 50))
slide.getBackground().setType(BackgroundType.OwnBackground)
image = Images.fromFile("image.png")
try:
preview_image = presentation.getImages().addImage(image)
finally:
image.dispose()
section = presentation.getSections().addSection("Section 1", slide)
section_zoom_frame = overview_slide.getShapes().addSectionZoomFrame(20, 20, 300, 200, section, preview_image)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Modifier la section cible d’un zoom de section
Utilisez SectionZoomFrame.setTargetSection pour rediriger un zoom de section existant sans le recréer. Choisissez une section remplie dans la collection Presentation.getSections de la même présentation. L’affectation d’une section vide laisse la cible actuelle inchangée, il faut donc vérifier Section.getSlidesListOfSection avant de l’affecter. Consultez Manage Slide Sections pour plus d’informations sur les sections.
L’exemple suivant charge un fichier de présentation, qui doit contenir plusieurs sections remplies, un zoom de section existant nommé Section navigation, et une section portant le nom unique Results. Il recherche le zoom parmi toutes les diapositives et trouve la destination par son nom plutôt que par un indice de collection qui peut changer lorsque les sections sont réordonnées. Si les noms ne sont pas uniques, utilisez Section.getSectionId pour identifier la destination à la place.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, SaveFormat, SectionZoomFrame
presentation = Presentation("section-zoom.pptx")
try:
zoom = None
for slide in presentation.getSlides():
for shape in slide.getShapes():
if isinstance(shape, SectionZoomFrame) and shape.getName() == "Section navigation":
zoom = shape
break
if zoom is not None:
break
target_section = None
for section in presentation.getSections():
if section.getName() == "Results":
target_section = section
break
if zoom is None or target_section is None:
print("The section zoom or destination section was not found.")
elif target_section.getSlidesListOfSection().size() == 0:
print("The destination section is empty.")
else:
current_section = zoom.getTargetSection()
current_name = "" if current_section is None else current_section.getName()
print("Current section: " + str(current_name))
zoom.setTargetSection(target_section)
presentation.save("section-zoom-updated.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Mettre en forme les cadres de zoom de section
Cet exemple déplace et redimensionne un zoom de section à 100 × 75 points, attribue une image locale via ZoomObject.setZoomImage, et applique une bordure brune pointillée de 2,5 points. Il active ZoomObject.setReturnToParent pour revenir à la diapositive d’origine après la section, désactive ZoomObject.setShowBackground, et définit ZoomObject.setTransitionDuration à 1,5 seconde. Une image locale est requise pour l’aperçu personnalisé.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Images, LineDashStyle, Presentation, SaveFormat
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(154, 205, 50))
slide.getBackground().setType(BackgroundType.OwnBackground)
section = presentation.getSections().addSection("Section 1", slide)
section_zoom_frame = overview_slide.getShapes().addSectionZoomFrame(20, 20, 300, 200, section)
section_zoom_frame.setX(100)
section_zoom_frame.setY(300)
section_zoom_frame.setWidth(100)
section_zoom_frame.setHeight(75)
image = Images.fromFile("image.png")
try:
preview_image = presentation.getImages().addImage(image)
finally:
image.dispose()
section_zoom_frame.setZoomImage(preview_image)
section_zoom_frame.setReturnToParent(True)
section_zoom_frame.setShowBackground(False)
section_zoom_frame.getLineFormat().getFillFormat().setFillType(FillType.Solid)
section_zoom_frame.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color(165, 42, 42))
section_zoom_frame.getLineFormat().setDashStyle(LineDashStyle.DashDot)
section_zoom_frame.getLineFormat().setWidth(2.5)
section_zoom_frame.setTransitionDuration(1.5)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Zoom de résumé
Un zoom de résumé fournit un aperçu des sections de la présentation. Pendant un diaporama, vous pouvez l’utiliser pour accéder à une section, avancer rapidement ou revisiter un sujet sans suivre l’ordre des diapositives.

Pour les objets de zoom de résumé, Aspose.Slides fournit les classes SummaryZoomFrame, SummaryZoomSection, et SummaryZoomSectionCollection ainsi que les méthodes de la classe ShapeCollection.
Créer un zoom de résumé
Utilisez ShapeCollection.addSummaryZoomFrame pour créer un aperçu des sections de la présentation. Cet exemple crée quatre sections avec des arrière-plans de diapositives distincts et ajoute un zoom de résumé à la première diapositive. La position et les dimensions du cadre sont spécifiées en points, et l’aperçu résultant est enregistré dans une présentation PPTX.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Presentation, SaveFormat
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(165, 42, 42))
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 1", slide)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color.CYAN)
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 2", slide)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(127, 255, 0))
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 3", slide)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(0, 100, 0))
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 4", slide)
summary_zoom_frame = overview_slide.getShapes().addSummaryZoomFrame(150, 50, 300, 200)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Ajouter et supprimer une section de zoom de résumé
Un zoom de résumé stocke ses objets SummaryZoomSection dans SummaryZoomFrame.getSummaryZoomCollection. Cet exemple crée un aperçu de deux sections, ajoute une troisième section avec SummaryZoomSectionCollection.addSummaryZoomSection, et supprime l’entrée de la première section à l’aide de SummaryZoomSectionCollection.removeSummaryZoomSection. La suppression de l’entrée laisse la section de la présentation et ses diapositives intactes.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Presentation, SaveFormat
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(165, 42, 42))
slide.getBackground().setType(BackgroundType.OwnBackground)
first_section = presentation.getSections().addSection("Section 1", slide)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color.CYAN)
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 2", slide)
summary_zoom_frame = overview_slide.getShapes().addSummaryZoomFrame(150, 50, 300, 200)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(127, 255, 0))
slide.getBackground().setType(BackgroundType.OwnBackground)
third_section = presentation.getSections().addSection("Section 3", slide)
summary_zoom_frame.getSummaryZoomCollection().addSummaryZoomSection(third_section)
summary_zoom_frame.getSummaryZoomCollection().removeSummaryZoomSection(first_section)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Mettre en forme les sections du zoom de résumé
Cet exemple met en forme la première entrée de SummaryZoomFrame.getSummaryZoomCollection, en utilisant l’indice zéro base 0. Il nécessite une image locale pour ZoomObject.setZoomImage, applique une bordure noire pointillée de 1,5 point, et définit ZoomObject.setTransitionDuration à 1,5 seconde. Passer False à ZoomObject.setReturnToParent désactive le retour automatique à la diapositive de résumé pour cette entrée.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BackgroundType, FillType, Images, LineDashStyle, Presentation, SaveFormat
from java.awt import Color
presentation = Presentation()
try:
overview_slide = presentation.getSlides().get_Item(0)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color(165, 42, 42))
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 1", slide)
slide = presentation.getSlides().addEmptySlide(overview_slide.getLayoutSlide())
slide.getBackground().getFillFormat().setFillType(FillType.Solid)
slide.getBackground().getFillFormat().getSolidFillColor().setColor(Color.CYAN)
slide.getBackground().setType(BackgroundType.OwnBackground)
presentation.getSections().addSection("Section 2", slide)
summary_zoom_frame = overview_slide.getShapes().addSummaryZoomFrame(150, 50, 300, 200)
summary_section = summary_zoom_frame.getSummaryZoomCollection().get_Item(0)
image = Images.fromFile("image.png")
try:
preview_image = presentation.getImages().addImage(image)
finally:
image.dispose()
summary_section.setZoomImage(preview_image)
summary_section.setReturnToParent(False)
summary_section.getLineFormat().getFillFormat().setFillType(FillType.Solid)
summary_section.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
summary_section.getLineFormat().setDashStyle(LineDashStyle.DashDot)
summary_section.getLineFormat().setWidth(1.5)
summary_section.setTransitionDuration(1.5)
presentation.save("presentation.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
FAQ
Puis-je contrôler le retour à la diapositive ‘parent’ après avoir affiché la cible ?
Oui. Appelez ZoomObject.setReturnToParent avec True pour revenir à la diapositive d’origine après l’affichage du contenu cible.
Puis-je ajuster la ‘vitesse’ ou la durée de la transition du Zoom ?
Oui. Utilisez ZoomObject.setTransitionDuration pour contrôler la durée de la transition en secondes.
Existe-t-il des limites au nombre d’objets Zoom qu’une présentation peut contenir ?
Il n’existe aucune limite d’API stricte documentée. Les limites pratiques dépendent de la complexité globale de la présentation et des performances du visualiseur. Vous pouvez ajouter de nombreux cadres de Zoom, mais il faut prendre en compte la taille du fichier et le temps de rendu.