convert method

convert

Converts the source document and saves the entire converted document.

Learn more:

def convert(self, target_stream_provider, convert_options):
    ...
Parameter Type Description
target_stream_provider Func[SaveContext, io.RawIOBase] Callable that receives a stream and saves the converted document to it.
convert_options ConvertOptions Convert options specific to the desired target file type.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

def convert_document_to_pdf():
    # Instantiate Converter with the input document
    with Converter("./business-plan.docx") as converter:
        # Define conversion options for PDF output
        pdf_options = PdfConvertOptions()
        # Convert the document and save as PDF
        converter.convert("./business-plan.pdf", pdf_options)

if __name__ == "__main__":
    convert_document_to_pdf()

convert

Converts the source document and saves the whole converted document.

Learn more:

def convert(self, convert_options, document_completed):
    ...
Parameter Type Description
convert_options ConvertOptions The convert options specific to desired target file type.
document_completed Action[ConvertedContext] Delegate that receives the converted document stream. Signature: Action<ConvertedContext>. The ConvertedContext parameter contains the converted document stream and metadata.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

with open("input.docx", "rb") as stream:
    with Converter(stream) as converter:
        converter.convert("output.pdf", PdfConvertOptions())

convert

Converts the source document and saves the whole converted document.

Learn more:

def convert(self, target_stream_provider, convert_options_provider):
    ...
Parameter Type Description
target_stream_provider Func[SaveContext, io.RawIOBase] Callable[[SaveContext], io.RawIOBase] that provides the stream to save the converted document.
convert_options_provider Func[ConvertContext, ConvertOptions] Callable[[ConvertContext], GroupDocs.Conversion.ConvertOptions] that provides conversion options.

Returns: None.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

with open("input.docx", "rb") as stream:
    with Converter(stream) as converter:
        converter.convert(
            lambda ctx: open("output.pdf", "wb"),
            lambda ctx: PdfConvertOptions(),
            cancellationToken=None
        )

convert

Converts the source document and saves the whole converted document.

Learn more

def convert(self, convert_options_provider, document_completed):
    ...
Parameter Type Description
convert_options_provider Func[ConvertContext, ConvertOptions] Callable[[ConvertContext], GroupDocs.Conversion.ConvertOptions] Provides conversion options. The ConvertContext parameter contains information about the conversion operation.
document_completed Action[ConvertedContext] Callable[[ConvertedContext], None] Receives the converted document stream. The ConvertedContext parameter contains the converted document stream and metadata.

Returns: None.

convert

Converts the source document and saves the whole converted document.

Learn more:

def convert(self, file_path, convert_options):
    ...
Parameter Type Description
file_path str The file path to the source document.
convert_options ConvertOptions The convert options specific to the desired target file type.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

with open("input.docx", "rb") as stream:
    with Converter(stream) as converter:
        converter.convert("output.pdf", PdfConvertOptions())

convert

Converts the source document and saves the converted document page by page.

Learn more

def convert(self, target_stream_provider, convert_options_provider):
    ...
Parameter Type Description
target_stream_provider Func[SavePageContext, io.RawIOBase] Callable[[SavePageContext], io.RawIOBase] that provides a stream for saving each converted page. The SavePageContext parameter contains page number and document information.
convert_options_provider Func[ConvertContext, ConvertOptions] Callable[[ConvertContext], ConvertOptions] that provides conversion options. The ConvertContext parameter contains information about the conversion operation.

Returns: None.

convert

Converts the source document and saves the converted document page by page.

Learn more

def convert(self, target_stream_provider, convert_options):
    ...
Parameter Type Description
target_stream_provider Func[SavePageContext, io.RawIOBase] Callable that provides a stream for saving each converted page. Signature: Func<SavePageContext, Stream>. The SavePageContext parameter contains page number and document information.
convert_options ConvertOptions The convert options specific to the desired target file type.

Returns: None.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

with open("input.docx", "rb") as stream:
    with Converter(stream) as converter:
        converter.convert("output.pdf", PdfConvertOptions())

convert

Converts the source document and saves the converted document page by page.

Learn more

def convert(self, convert_options, document_completed):
    ...
Parameter Type Description
convert_options ConvertOptions The convert options specific to desired target file type.
document_completed Action[ConvertedPageContext] Callable that receives each converted page. The ConvertedPageContext parameter contains page number, stream, source file name, and target file type.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

with Converter("./business-plan.docx") as converter:
    converter.convert("./business-plan.pdf", PdfConvertOptions())

convert

Converts the source document and saves the converted document page by page.

Learn more

def convert(self, convert_options_provider, document_completed):
    ...
Parameter Type Description
convert_options_provider Func[ConvertContext, ConvertOptions] Delegate that provides conversion options. The ConvertContext parameter contains information about the conversion operation.
document_completed Action[ConvertedPageContext] Delegate that receives each converted page. The ConvertedPageContext parameter contains page number, stream, source file name, and target file type.

Example

from groupdocs.conversion import Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

with open("input.docx", "rb") as stream:
    with Converter(stream) as converter:
        converter.convert("output.pdf", PdfConvertOptions())

See Also