从 PPTX 中提取自由形状并使用 Python 进行绘图

问题描述 投票:0回答:1

我正在开发一个项目,需要从 PowerPoint (PPTX) 文件中提取自由形状,然后使用 Python 绘制它们。我已经探索了各种库,例如用于读取 PPTX 文件的 python-pptx,但我正在努力专门提取自由形状。

我搜索并发现了这个:如何从 ppt 中提取 FREEFORM 形状并使用 pptx 将其保存在 png 文件中但这还不够。

我设法通过使用 aspose 转换为 html 来解决它,但我不想使用在线服务。

我正在寻找无服务的解决方案。我愿意切换/添加另一种编程语言

python powerpoint python-pptx
1个回答
0
投票

使用 Aspose.Slides for Python,您可以像这样提取自由形状:

with slides.Presentation("sample.pptx") as presentation:
    first_slide = presentation.slides[0]
    for shape in first_slide.shapes:
        if isinstance(shape, GeometryShape):
            print("Shape name:", shape.name)
            for path in shape.get_geometry_paths():
                for segment in path.path_data:
                    print(segment.path_command)
                    for data in segment.segment_data:
                        print(data, end = "; ")
                    print()
            print()

输出示例:

Shape name: Freeform: Shape 2
PathCommandType.MOVE_TO
0.0; 65.50377655029297; 
PathCommandType.LINE_TO
54.13536071777344; 2.165432929992676; 
PathCommandType.LINE_TO
61.17292022705078; 0.0; 
PathCommandType.CUBIC_BEZIER_TO
61.37685775756836; 0.09062991291284561; 71.41165924072266; 3.154172897338867; 73.08268737792969; 6.496220111846924; 

API 参考:演示文稿GeometryShapePathCommandType

文档:Aspose.Slides for Python via .NET

© www.soinside.com 2019 - 2024. All rights reserved.