converter.convert("output.png", convert_options)
RuntimeError: Proxy error(GroupDocsConversionException): Saving complete document is only supported when converting to tiff —> NotSupportedException: Saving complete document is only supported when converting to tiff
input.docx (303.7 KB)
import os
from groupdocs.conversion import License, Converter
from groupdocs.conversion.options.convert import ImageConvertOptions
from groupdocs.conversion.filetypes import ImageFileType
# If you have a license, uncomment the following lines to set it
license_path = os.path.abspath("./GroupDocs.Conversion.lic")
if os.path.exists(license_path):
# Create License and set the path
license = License()
license.set_license(license_path)
# Load the source DOCX file
converter = Converter("input.docx")
# Set conversion options for JPG format
convert_options = ImageConvertOptions()
# Set output image format as JPG
convert_options.format = ImageFileType.PNG
# Convert DOCX to JPG
converter.convert("output.png", convert_options)
# Print success message
print("Conversion completed successfully.")
@tahir.manzoor
The error you are encountering indicates that saving the complete document as an image is only supported when converting to TIFF format. This limitation arises because the conversion library you are using does not support saving the entire document as a PNG or JPG image.
To resolve this issue, you can either convert the document to TIFF format or specify a page range for conversion. If you want to convert only a specific page of the DOCX file to PNG, you can modify your code to set the pagesCount
property in the conversion options.
Here’s an example of how to adjust your code to convert only the first page of the DOCX file to PNG:
import os
from groupdocs.conversion import License, Converter
from groupdocs.conversion.options.convert import ImageConvertOptions
from groupdocs.conversion.filetypes import ImageFileType
# If you have a license, uncomment the following lines to set it
license_path = os.path.abspath("./GroupDocs.Conversion.lic")
if os.path.exists(license_path):
# Create License and set the path
license = License()
license.set_license(license_path)
# Load the source DOCX file
converter = Converter("input.docx")
# Set conversion options for PNG format
convert_options = ImageConvertOptions()
# Set output image format as PNG
convert_options.format = ImageFileType.PNG
# Specify the number of pages to convert (e.g., 1 for the first page)
convert_options.pages_count = 1
# Convert DOCX to PNG
converter.convert("output.png", convert_options)
# Print success message
print("Conversion completed successfully.")
In this modified code, the pages_count
property is set to 1
, which means only the first page of the document will be converted to PNG format. If you need to convert more pages, you can adjust this value accordingly.
If you still want to convert the entire document to TIFF, you can change the output format in the convert_options
to ImageFileType.TIFF
.
Feel free to ask if you have any further questions!
@tahir.manzoor
To properly convert multipage documents to pages e.g. DOCX to PNG you have to use convert_by_page
method which is designed for such cases:
Three methods are available for converting documents into multiple-page files:
convert_by_page(folder_path, convert_options)
: Converts the document into individual pages, saving each page as a separate file in the specified directory.
convert_by_page(page_path, page_number, convert_options)
: Converts specific document pages and saves each page to a specified file path.
convert_by_page(page_stream, page_number, convert_options)
: Converts specific document pages and saves them to a specified stream.
This is taken from Converting Documents topic.
The actual examples of converting documents to pages you can find in Convert a Document to Multiple Page Files topic.
And here is code snippet to convert DOCX to PNG:
from groupdocs.conversion import Converter
from groupdocs.conversion.filetypes import ImageFileType
from groupdocs.conversion.options.convert import ImageConvertOptions
def convert_all_document_pages():
# Instantiate Converter with the input document
with Converter("./input.docx") as converter:
# Instantiate convert options
png_convert_options = ImageConvertOptions()
# Define the output format as PNG
png_convert_options.format = ImageFileType.PNG
# Convert all pages and save to the output folder
converter.convert_by_page("./converted-pages", png_convert_options)
if __name__ == "__main__":
convert_all_document_pages()