Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 4, 2021 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/b34557af65be5264d357aa828e9e3f67 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b34557af65be5264d357aa828e9e3f67 to your computer and use it in GitHub Desktop.
Convert Word Documents to PNG, JPEG, BMP in Python
import aspose.words as aw
# load document
doc = aw.Document("calibre.docx")
# set output image format
options = aw.saving.ImageSaveOptions(aw.SaveFormat.PNG)
options = aw.saving.ImageSaveOptions(aw.SaveFormat.JPEG)
# change the image's brightness and contrast
# both are on a 0-1 scale and are at 0.5 by default
options.image_brightness = 0.3
options.image_contrast = 0.7
# change the horizontal resolution
# the default value for these properties is 96.0, for a resolution of 96dpi
options.horizontal_resolution = 72
# loop through pages and convert them as PNG images
for pageNumber in range(doc.page_count):
options.page_set = aw.saving.PageSet(pageNumber)
doc.save(str(pageNumber+1)+"_page.png", options)
import aspose.words as aw
# load document
doc = aw.Document("calibre.docx")
# set output image format
options = aw.saving.ImageSaveOptions(aw.SaveFormat.PNG)
# loop through pages and convert them to PNG images
for pageNumber in range(doc.page_count):
options.page_set = aw.saving.PageSet(pageNumber)
doc.save(str(pageNumber+1)+"_page.png", options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment