python-pptx
python-pptx copied to clipboard
Generating corrupted PPT when using connectors
I have observed an issue recently with the library where the generated PPT doesn't open in Google Slides and Microsoft Powerpoint
You can have a look at the below example
for i in range(len(positions) - 1):
keys = list(positions.keys())
start_shape = shapes[keys[i]]
end_shape = shapes[keys[i + 1]]
# Calculate the absolute positions for start and end points
start_left = start_shape.left + start_shape.width
start_top = start_shape.top + start_shape.height / 2
end_left = end_shape.left
end_top = end_shape.top + end_shape.height / 2
connector = slide.shapes.add_connector(
MSO_CONNECTOR.CURVE,
start_left,
start_top,
end_left,
end_top
)
I have observed that when the start_top and end_top are not integers because of the division. The PPT generated doesn't open in Google Slides and Microsoft PPT.
start_top = start_shape.top + int(start_shape.height / 2)
end_top = end_shape.top + int(end_shape.height / 2)
and this fixes the issue. I was thinking of moving this inside the library itself, so that even if the client sends a non-int value, it can be cast to a int value and the PPT generated will be valid.
Let me know if I can raise of PR for this @scanny