convert method

convert(input_file, output_file)

Converts the given input document into the output document using specified input output file names and its extensions.

def convert(self, input_file: str, output_file: str):
    ...
ParameterTypeDescription
input_filestrThe input file name.
output_filestrThe output file name.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

convert(input_file, output_file, save_format)

Converts the given input document into the output document using specified input output file names and the final document format.

def convert(self, input_file: str, output_file: str, save_format: aspose.words.SaveFormat):
    ...
ParameterTypeDescription
input_filestrThe input file name.
output_filestrThe output file name.
save_formatSaveFormatThe save format.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

convert(input_file, output_file, save_options)

Converts the given input document into the output document using specified input output file names and save options.

def convert(self, input_file: str, output_file: str, save_options: aspose.words.saving.SaveOptions):
    ...
ParameterTypeDescription
input_filestrThe input file name.
output_filestrThe output file name.
save_optionsSaveOptionsThe save options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

convert(input_file, load_options, output_file, save_options)

Converts the given input document into the output document using specified input output file names its load/save options.

def convert(self, input_file: str, load_options: aspose.words.loading.LoadOptions, output_file: str, save_options: aspose.words.saving.SaveOptions):
    ...
ParameterTypeDescription
input_filestrThe input file name.
load_optionsLoadOptionsThe input document load options.
output_filestrThe output file name.
save_optionsSaveOptionsThe save options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

convert(input_stream, output_stream, save_format)

Converts the given input document into a single output document using specified input and output streams.

def convert(self, input_stream: io.BytesIO, output_stream: io.BytesIO, save_format: aspose.words.SaveFormat):
    ...
ParameterTypeDescription
input_streamio.BytesIOThe input stream.
output_streamio.BytesIOThe output stream.
save_formatSaveFormatThe save format.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

convert(input_stream, output_stream, save_options)

Converts the given input document into a single output document using specified input and output streams.

def convert(self, input_stream: io.BytesIO, output_stream: io.BytesIO, save_options: aspose.words.saving.SaveOptions):
    ...
ParameterTypeDescription
input_streamio.BytesIOThe input streams.
output_streamio.BytesIOThe output stream.
save_optionsSaveOptionsThe save options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

convert(input_stream, load_options, output_stream, save_options)

Converts the given input document into a single output document using specified input and output streams.

def convert(self, input_stream: io.BytesIO, load_options: aspose.words.loading.LoadOptions, output_stream: io.BytesIO, save_options: aspose.words.saving.SaveOptions):
    ...
ParameterTypeDescription
input_streamio.BytesIOThe input streams.
load_optionsLoadOptionsThe input document load options.
output_streamio.BytesIOThe output stream.
save_optionsSaveOptionsThe save options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

Examples

Shows how to convert documents with a single line of code.

doc = MY_DIR + 'Document.docx'
aw.lowcode.Converter.convert(input_file=doc, output_file=ARTIFACTS_DIR + 'LowCode.Convert.pdf')
aw.lowcode.Converter.convert(input_file=doc, output_file=ARTIFACTS_DIR + 'LowCode.Convert.SaveFormat.rtf', save_format=aw.SaveFormat.RTF)
save_options = aw.saving.OoxmlSaveOptions()
save_options.password = 'Aspose.Words'
load_options = aw.loading.LoadOptions()
load_options.ignore_ole_data = True
aw.lowcode.Converter.convert(input_file=doc, load_options=load_options, output_file=ARTIFACTS_DIR + 'LowCode.Convert.LoadOptions.docx', save_options=save_options)
aw.lowcode.Converter.convert(input_file=doc, output_file=ARTIFACTS_DIR + 'LowCode.Convert.SaveOptions.docx', save_options=save_options)

Shows how to convert documents with a single line of code (Stream).

with system_helper.io.FileStream(MY_DIR + 'Big document.docx', system_helper.io.FileMode.OPEN, system_helper.io.FileAccess.READ) as stream_in:
    with system_helper.io.FileStream(ARTIFACTS_DIR + 'LowCode.ConvertStream.1.docx', system_helper.io.FileMode.CREATE, system_helper.io.FileAccess.READ_WRITE) as stream_out:
        aw.lowcode.Converter.convert(input_stream=stream_in, output_stream=stream_out, save_format=aw.SaveFormat.DOCX)
    save_options = aw.saving.OoxmlSaveOptions()
    save_options.password = 'Aspose.Words'
    load_options = aw.loading.LoadOptions()
    load_options.ignore_ole_data = True
    with system_helper.io.FileStream(ARTIFACTS_DIR + 'LowCode.ConvertStream.2.docx', system_helper.io.FileMode.CREATE, system_helper.io.FileAccess.READ_WRITE) as stream_out:
        aw.lowcode.Converter.convert(input_stream=stream_in, load_options=load_options, output_stream=stream_out, save_options=save_options)
    with system_helper.io.FileStream(ARTIFACTS_DIR + 'LowCode.ConvertStream.3.docx', system_helper.io.FileMode.CREATE, system_helper.io.FileAccess.READ_WRITE) as stream_out:
        aw.lowcode.Converter.convert(input_stream=stream_in, output_stream=stream_out, save_options=save_options)

See Also