Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 24, 2024 02:36

Revisions

  1. aspose-com-gists revised this gist Nov 4, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    Learn how to convert Word documents to PNG, JPEG, and BMP images in Python:
    Learn how to convert Word documents to PNG, JPEG, and BMP images in Python: https://blog.aspose.com/2021/11/04/convert-word-to-png-jpg-bmp-in-python/
  2. aspose-com-gists created this gist Nov 4, 2021.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Learn how to convert Word documents to PNG, JPEG, and BMP images in Python:
    23 changes: 23 additions & 0 deletions word-to-image-custom.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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)
    12 changes: 12 additions & 0 deletions word-to-image.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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)