Learn how to Convert Photo to Word in Python
Last active
September 21, 2024 05:11
Convert Photo to Word in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example shows how to convert a photo to a Word document in DOC format using Python. | |
import aspose.words as aw | |
# Create a new document | |
doc = aw.Document() | |
# Create a document builder | |
builder = aw.DocumentBuilder(doc) | |
# Insert photo into the document | |
builder.insert_image("tower.jpg") | |
# Save as DOC | |
doc.save("Output.doc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example shows how to add multiple photos to a Word document using Python. | |
import os | |
import aspose.words as aw | |
# Image directory | |
dir = "D:\\Files\\Images\\" | |
# Create a new document | |
doc = aw.Document() | |
# Create a document builder | |
builder = aw.DocumentBuilder(doc) | |
# Loop through images in folder | |
for imageFile in os.listdir(dir): | |
# Insert image into the document | |
builder.insert_image(os.path.join(dir, imageFile)) | |
# Save as DOCX | |
doc.save("D:\\Files\\photos-to-word.docx") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example shows how to add photos into an existing Word document using Python. | |
import aspose.words as aw | |
from aspose.words import BreakType | |
# create new document | |
doc = aw.Document("Document.docx"); | |
# create and initialize document builder | |
builder = aw.DocumentBuilder(doc); | |
# move to the end of the document | |
builder.move_to_document_end(); | |
# insert a new page | |
builder.insert_break(BreakType.PAGE_BREAK); | |
# insert picture to document | |
builder.insert_image("tower.jpg"); | |
# save the document | |
doc.save("Output_1.docx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment