To load a source file from your local disk, you can use the Converter class constructor in GroupDocs.Conversion. The API offers several overloads, allowing flexibility for various settings and options:
Each constructor requires the filePath parameter, which defines the path to the source file. You can specify this as an absolute or relative path. Note that if the specified file path does not exist, an exception will be raised.
Tip
GroupDocs.Conversion will access the file only when an action (e.g., conversion) is performed using the Converter class instance.
The following Python example demonstrates loading a file from a local disk and converting it to PDF:
fromgroupdocs.conversionimportConverterfromgroupdocs.conversion.options.convertimportPdfConvertOptionsdefconvert_docx_to_pdf():# Specify source file locationconverter=Converter("./business-plan.docx")# Specify output file location and convert optionsoutput_path="./business-plan.pdf"pdf_options=PdfConvertOptions()# Convert and save to output pathconverter.convert(output_path,pdf_options)if__name__=="__main__":convert_docx_to_pdf()
business-plan.docx is sample file used in this example. Click here to download it.
business-plan.pdf is converted PDF document. Click here to download it.
Warning
GroupDocs.Conversion determines the file type by its extension. If the file extension is not set, GroupDocs.Conversion will attempt to detect the file type automatically. Depending on the file type and size, automatic file type detection consumes additional resources, such as memory and CPU time. Therefore, we recommend ensuring that a file has the correct extension or using the Converter class constructor that accepts load options.
Explanation
Load Source File: The Converter class is instantiated with the path to the source document (“business-plan.docx”).
Conversion Options: An instance of PdfConvertOptions is created to define the settings for PDF conversion.
Execute Conversion: The convert method is used to convert the document and save it to the specified output path (“business-plan.pdf”).