Location>code7788 >text

Python Convert Word to JPG, PNG, SVG Images

Popularity:306 ℃/2024-08-05 16:25:06

 

Python Convert Word to JPG, JPEG, PNG, BMP and other image formats

from  import *
from  import *
 
# Loading Word documents
document = Document()
("Experiment.docx")
 
# Iterate over all pages
for i in range(()):
    # Converts a given page to an image stream
    imageStream = (i, )
    # Save as a .png image (can also be saved as an image format such as jpg or bmp)
    with open("Image\\\\tu-{0}.png".format(i),'wb') as imageFile:
        (())
        
# Close Document
()

The above code is passed through the() The method converts the pages in a Word document into a stream of images, after which the stream is saved as an image file in the specified format. The generated file for converting Word to PNG image is as follows:

 

 

Python Converting Word Documents to SVG Format

SVG images are an XML-based vector graphics format that allows the creation of scalable, editable graphics that are ideal for use in web design, iconography, applications, and all kinds of graphic design. In for Python, Word to SVG can be converted directly using the(fileName, ) Methods.

from  import *
from  import *
 
# Loading Word documents
document = Document()
("Experiment.docx")
 
# Convert to SVG file
("To SVG\\\\", )
()

The generated file is shown in the figure:

 


 

※ If you want to fully test this Python Word library and remove the watermark, you can click to request a trial license:Request a free temporary authorization document