1.安装库aspose-words
pip install aspose-words
2.参考代码:
待转换文件: 1.docx
转换后目录: pic/Output_*.jpg
def cut_pic(image_path):
# 打开图片
image = Image.open(image_path)
# 获取图片尺寸
width, height = image.size
# 计算裁减的起始和结束位置
left = 0
top = int(height * 0.10245)
right = width
bottom = height - int(height * 0.08999)
# 裁减图片
cropped_image = image.crop((left, top, right, bottom))
# 保存裁减后的图片
cropped_image.save(image_path)
def word_img():
import aspose.words as aw
doc = aw.Document('1.docx')
for page in range(0, doc.page_count):
extractedPage = doc.extract_pages(page, 1)
extractedPage.save(f"pic/Output_{page + 1}.jpg")
cut_pic(file_path)
if __name__ == '__main__':
word_img()