Aspose.Slides for Python Creates a Corrupted PowerPoint Presentation

“Please help. I’m using Aspose Slides for Python, and I want to create a presentation about the seasons. However, I made a mistake somewhere, and the presentation is corrupted, and I can’t open it or determine the error. Could you please assist me with this?”

import aspose.slides as slides
import aspose.pydrawing as draw
import datetime
# Создаем новую презентацию
presentation = slides.Presentation()
license = slides.License()

# Sets the license file path
license.set_license("license.lic")
# Создаем слайды и добавляем их в презентацию
seasons = ["Весна", "Лето", "Осень", "Зима"]
descriptions = [
    "Время цветения природы и расцветающих цветов. \n Весной всё оживает, и природа просыпается от зимней спячки. В это время года можно наслаждаться яркими цветами и пение птиц.",
    "Теплое время года с ярким солнцем и отпусками на море. \n Летом можно наслаждаться жаркими днями, купаться в море, загорать и устраивать пикники на свежем воздухе.",
    "Период урожая и падения листьев с деревьев. \n Осень прекрасна своими красочными лесами и урожаем. Это время года, когда природа готовится к зиме.",
    "Холодное время снега и зимних видов активного отдыха. \n Зимой можно кататься на лыжах и катке, а также праздновать новогодние праздники в уютной обстановке с теплым чаем."
]

# slide = presentation.slides.add_slide(presentation.slide_layouts[5])  # 5 - это индекс макета для текстового слайда
#presentation.slides[0].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 200, 200, 200) 

    # Добавляем текст времени года и его более длинное описание на слайд
#slides.name = season
documentProperties = presentation.document_properties # Set the builtin properties 
documentProperties.author = "NullPtr" 
documentProperties.title = "Aspose Presentation" 
documentProperties.subject = "Aspose Subject" 
documentProperties.comments = "Aspose comments" 
documentProperties.manager = "Aspose Manager"
#for i in range(len(presentation.layout_slides)): # Add an empty slide to the Slides collection slds.add_empty_slide(pres.layout_slides[i])
    #layoutSlide = layoutSlides.masters[0].get_by_type(slides.SlideLayoutType.BLANK)
for i in range(len(seasons)):
    layoutSlide = presentation.masters[0].layout_slides.get_by_type(slides.SlideLayoutType.BLANK)
    presentation.slides.add_empty_slide(layoutSlide) 
    author = presentation.comment_authors.add_author("NullPtr", "MF") # Sets the position for comments 
    point = draw.PointF(0.2, 0.2) # Adds slide comment for an author on slide 1 
    author.comments.add_comment(descriptions[i], presentation.slides[i], point, datetime.date.today()) # Adds slide comment for an author on slide 2 
    slide = presentation.slides[i] # When null is passed as an argument, comments from all authors are brought to the selected slide
    autoShape = presentation.slides[i].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 150, 75, 150, 50) # Adds TextFrame to the Rectangle 
    autoShape.add_text_frame(" ")
    paragraph = autoShape.text_frame.paragraphs[0] # add Fly animation effect to selected paragraph 
    effect = presentation.slides[i].timeline.main_sequence.add_effect(paragraph, slides.animation.EffectType.FLY, slides.animation.EffectSubtype.LEFT, slides.animation.EffectTriggerType.ON_CLICK) 
    paragraph = slides.Paragraph() 
    paragraph.text = descriptions[i] # Setting paragraph bullet style and image 
    paragraph.paragraph_format.bullet.type = slides.BulletType.PICTURE 
    #paragraph.paragraph_format.bullet.picture.image = ippxImage # Setting Bullet Height 
    paragraph.paragraph_format.bullet.height = 100 # Adding Paragraph to text frame 
    shape = presentation.slides[i].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 150, 250, 250) 
    shape.add_text_frame(" ")
    #shape.fill_format.fill_type = slides.FillType.NO_FILL 
    #shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL 

    portion = shape.text_frame.paragraphs[0].portions[0] 
    portion.portion_format.fill_format.fill_type = slides.FillType.PATTERN
    portion.portion_format.fill_format.pattern_format.fore_color.color = draw.Color.dark_orange 
    portion.portion_format.fill_format.pattern_format.back_color.color = draw.Color.white 
    portion.portion_format.fill_format.pattern_format.pattern_style = slides.PatternStyle.LARGE_GRID 
    portion.text=seasons[i]
    shape.text_frame.paragraphs[0].paragraph_format.default_portion_format.font_height = 128 
    textFrame = shape.text_frame # setup "Arch Up" WordArt transform effect 
    textFrame.text_frame_format.transform = slides.TextShapeType.ARCH_UP 
    textFrame.text_frame_format.three_d_format.extrusion_height = 3.5 
    textFrame.text_frame_format.three_d_format.depth = 3 
    textFrame.text_frame_format.three_d_format.material = slides.MaterialPresetType.PLASTIC 
    textFrame.text_frame_format.three_d_format.light_rig.direction = slides.LightingDirection.TOP 
    textFrame.text_frame_format.three_d_format.light_rig.light_type = slides.LightRigPresetType.BALANCED 
    textFrame.text_frame_format.three_d_format.light_rig.set_rotation(0, 0, 40) 
    textFrame.text_frame_format.three_d_format.camera.camera_type = slides.CameraPresetType.PERSPECTIVE_CONTRASTING_RIGHT_FACING
    presentation.slides[i].get_thumbnail(2, 2).save("text3d.png") #pres.save("text3d.pptx", slides.export.SaveFormat.PPTX)
    textFrame.paragraphs.add(paragraph)

# Instantiates the License class 


    # Настраиваем анимацию для слайда (смена слайдов с анимацией)
# Сохраняем презентацию в файл
presentation.save("example.pptx", slides.export.SaveFormat.PPTX)

@Mahadhj2b,
Thank you for contacting support. I am working on the issue and will get back to you as soon as possible.

@Mahadhj2b,
I’ve reproduced the problem you described.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESPYNET-121

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

there is a workaround to fix a corrupted presentation, for example by resaving it in some program for android or when the problem will be fixed?

@Mahadhj2b,
Unfortunately, I don’t see a workaround for the case. Our developers will do their best to resolve the issue.

@Mahadhj2b,
Please take a look at the following line in your code example:

author = presentation.comment_authors.add_author("NullPtr", "MF") # Sets the position for comments

The author of the comment should be added once. In the provided code example, the comment author is added several times in a loop. We will implement throwing an exception when adding the same author. The correct snippet:

import aspose.slides as slides
import aspose.slides.export as export
import aspose.pydrawing as draw
import datetime

presentation = slides.Presentation()

seasons = ["Весна", "Лето", "Осень", "Зима"]
descriptions = [
    "Время цветения природы и расцветающих цветов. \n Весной всё оживает, и природа просыпается от зимней спячки. В это время года можно наслаждаться яркими цветами и пение птиц.",
    "Теплое время года с ярким солнцем и отпусками на море. \n Летом можно наслаждаться жаркими днями, купаться в море, загорать и устраивать пикники на свежем воздухе.",
    "Период урожая и падения листьев с деревьев. \n Осень прекрасна своими красочными лесами и урожаем. Это время года, когда природа готовится к зиме.",
    "Холодное время снега и зимних видов активного отдыха. \n Зимой можно кататься на лыжах и катке, а также праздновать новогодние праздники в уютной обстановке с теплым чаем."
]

documentProperties = presentation.document_properties # Set the builtin properties
documentProperties.author = "NullPtr"
documentProperties.title = "Aspose Presentation"
documentProperties.subject = "Aspose Subject"
documentProperties.comments = "Aspose comments"
documentProperties.manager = "Aspose Manager"
author = presentation.comment_authors.add_author("NullPtr", "MF")  # you should add author here once

for i in range(len(seasons)):
    layoutSlide = presentation.masters[0].layout_slides.get_by_type(slides.SlideLayoutType.BLANK)
    presentation.slides.add_empty_slide(layoutSlide)
    # author = presentation.comment_authors.add_author("NullPtr", "MF") # Sets the position for comments
    point = draw.PointF(0.2, 0.2) # Adds slide comment for an author on slide 1
    author.comments.add_comment(descriptions[i], presentation.slides[i], point, datetime.date.today()) # Adds slide comment for an author on slide 2
    slide = presentation.slides[i] # When null is passed as an argument, comments from all authors are brought to the selected slide
    autoShape = presentation.slides[i].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 150, 75, 150, 50) # Adds TextFrame to the Rectangle
    autoShape.add_text_frame(" ")
    paragraph = autoShape.text_frame.paragraphs[0] # add Fly animation effect to selected paragraph
    effect = presentation.slides[i].timeline.main_sequence.add_effect(paragraph, slides.animation.EffectType.FLY, slides.animation.EffectSubtype.LEFT, slides.animation.EffectTriggerType.ON_CLICK)
    paragraph = slides.Paragraph()
    paragraph.text = descriptions[i] # Setting paragraph bullet style and image
    paragraph.paragraph_format.bullet.type = slides.BulletType.PICTURE
    #paragraph.paragraph_format.bullet.picture.image = ippxImage # Setting Bullet Height
    paragraph.paragraph_format.bullet.height = 100 # Adding Paragraph to text frame
    shape = presentation.slides[i].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 150, 250, 250)
    shape.add_text_frame(" ")
    #shape.fill_format.fill_type = slides.FillType.NO_FILL
    #shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL

    portion = shape.text_frame.paragraphs[0].portions[0]
    portion.portion_format.fill_format.fill_type = slides.FillType.PATTERN
    portion.portion_format.fill_format.pattern_format.fore_color.color = draw.Color.dark_orange
    portion.portion_format.fill_format.pattern_format.back_color.color = draw.Color.white
    portion.portion_format.fill_format.pattern_format.pattern_style = slides.PatternStyle.LARGE_GRID
    portion.text=seasons[i]
    shape.text_frame.paragraphs[0].paragraph_format.default_portion_format.font_height = 128
    textFrame = shape.text_frame # setup "Arch Up" WordArt transform effect
    textFrame.text_frame_format.transform = slides.TextShapeType.ARCH_UP
    textFrame.text_frame_format.three_d_format.extrusion_height = 3.5
    textFrame.text_frame_format.three_d_format.depth = 3
    textFrame.text_frame_format.three_d_format.material = slides.MaterialPresetType.PLASTIC
    textFrame.text_frame_format.three_d_format.light_rig.direction = slides.LightingDirection.TOP
    textFrame.text_frame_format.three_d_format.light_rig.light_type = slides.LightRigPresetType.BALANCED
    textFrame.text_frame_format.three_d_format.light_rig.set_rotation(0, 0, 40)
    textFrame.text_frame_format.three_d_format.camera.camera_type = slides.CameraPresetType.PERSPECTIVE_CONTRASTING_RIGHT_FACING
    presentation.slides[i].get_thumbnail(2, 2).save("text3d.png") #pres.save("text3d.pptx", slides.export.SaveFormat.PPTX)
    textFrame.paragraphs.add(paragraph)

presentation.save("output.pptx", slides.export.SaveFormat.PPTX)

More examples:

The issues you found earlier (filed as SLIDESPYNET-121) have been fixed in Aspose.Slides for Python 24.4 (Windows x86, Windows x64, Linux, macOS x86-x64, macOS ARM64).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page or PyPI.