Running Examples

This page provides instructions on how to set up and run code examples for GroupDocs.Conversion for Python via .NET. The examples are designed to demonstrate basic usage, including conversion between various file formats, working with files in archives, and retrieving document information.

Prerequisites

Before running the examples, make sure you have:

  1. Configured environment as described in the System Requirements topic.
  2. Downloaded or cloned the GitHub repository containing the examples.

Project Structure

The example repository is structured similarly to this documentation, making it easy to find the code examples and related input documents.

πŸ“‚ Examples
β”œβ”€β”€ getting-started
    β”œβ”€β”€ quick-start-guide
        β”œβ”€β”€ **convert_docx_to_pdf.py**
        β”œβ”€β”€ **convert_files_in_archive.py**
        β”œβ”€β”€ **convert_pdf_pages_to_png.py**
        β”œβ”€β”€ annual-review.pdf
        β”œβ”€β”€ business-plan.docx
        β”œβ”€β”€ compressed.zip
β”œβ”€β”€ developer-guide
    β”œβ”€β”€ loading-documents
        β”œβ”€β”€ get-default-load-options
            β”œβ”€β”€ **get_default_load_options.py**
        β”œβ”€β”€ load-file-from-local-disk
            β”œβ”€β”€ **convert_docx_to_pdf.py**
            β”œβ”€β”€ business-plan.docx
        β”œβ”€β”€ load-file-from-stream
            β”œβ”€β”€ **detect_file_type_automatically.py**
            β”œβ”€β”€ **load_file_from_stream.py**
            β”œβ”€β”€ annual-review.docx
        β”œβ”€β”€ load-password-protected-file
            β”œβ”€β”€ **load_password_protected_file.py**
            β”œβ”€β”€ password-protected.docx
    β”œβ”€β”€ get-document-info
        β”œβ”€β”€ **get_cad_document_info.py**
        β”œβ”€β”€ **get_document_info.py**
        β”œβ”€β”€ **get_email_document_info.py**
        β”œβ”€β”€ **get_image_document_info.py**
        β”œβ”€β”€ **get_pdf_document_info.py**
        β”œβ”€β”€ **get_pm_document_info.py**
        β”œβ”€β”€ **get_pres_document_info.py**
        β”œβ”€β”€ **get_sp_document_info.py**
        β”œβ”€β”€ **get_wp_document_info.py**
        β”œβ”€β”€ blocks-and-tables.dwg
        β”œβ”€β”€ business-plan.doc
        β”œβ”€β”€ cost-analysis.xlsx
        β”œβ”€β”€ infographic-elements.tiff
        β”œβ”€β”€ invitation.eml
        β”œβ”€β”€ lorem-ipsum.txt
        β”œβ”€β”€ presentation-template.pptx
        β”œβ”€β”€ sample-with-toc.pdf
        β”œβ”€β”€ weekly-plan.mpp
    β”œβ”€β”€ converting-documents
        β”œβ”€β”€ add-watermark-to-converted-document
            β”œβ”€β”€ **add_watermark_to_converted_document.py**
            β”œβ”€β”€ professional-services.docx
        β”œβ”€β”€ convert-document-to-another-format
            β”œβ”€β”€ **convert_consecutive_document_pages.py**
            β”œβ”€β”€ **convert_document_to_another_format.py**
            β”œβ”€β”€ **convert_specific_document_pages.py**
            β”œβ”€β”€ business-plan.docx
        β”œβ”€β”€ convert-document-to-multiple-page-files
            β”œβ”€β”€ **convert_all_document_pages.py**
            β”œβ”€β”€ **convert_specific_document_page_to_file.py**
            β”œβ”€β”€ **convert_specific_document_page_to_stream.py**
            β”œβ”€β”€ basic-presentation.pptx
            β”œβ”€β”€ converted-pages
        β”œβ”€β”€ convert-files-within-document-containers
            β”œβ”€β”€ **convert_files_within_document_container.py**
            β”œβ”€β”€ compressed.zip
            β”œβ”€β”€ converted-files
        β”œβ”€β”€ get-possible-conversions
            β”œβ”€β”€ **get_all_possible_conversions.py**
            β”œβ”€β”€ **get_all_possible_conversions_by_file_extension.py**
            β”œβ”€β”€ **get_all_possible_conversions_for_current_file.py**
            β”œβ”€β”€ cost-analysis.xlsx
    β”œβ”€β”€ logging-and-diagnostics
        β”œβ”€β”€ **write_logs_to_console.py**
        β”œβ”€β”€ **write_logs_to_file.py**
        β”œβ”€β”€ business-plan.docx
β”œβ”€β”€ licensing
    β”œβ”€β”€ **set_license_from_file.py**
    β”œβ”€β”€ **set_license_from_stream.py**
    β”œβ”€β”€ **set_metered_license.py**
β”œβ”€β”€ **run_all_examples.py**
β”œβ”€β”€ requirements.txt

Setup Instructions

  1. Create and Activate Virtual Environment: Navigate to the project root directory with cd ./Examples. Then create and activate virtual environment:

    Create a virtual environment:

    py -m venv .venv
    
    python3 -m venv .venv
    

    Activate a virtual environment:

    .venv\Scripts\activate
    
    source .venv/bin/activate
    

Install the Dependencies

After activating the virtual environment, run the following command in your terminal to install the dependencies:

py -m pip install -r requirements.txt
python3 -m pip install -r requirements.txt
  1. Configure License (Optional): If you have a license file, you can set the license path in the run_all_examples.py file. By default, GroupDocs.Conversion for Python via .NET looks for the GROUPDOCS_LIC_PATH environment variable or for files with the .lic extension in the project’s root directory.

    Note
    Learn more about licensing, evaluation, and how to obtain a temporary license in the Licensing documentation topic.

Running Examples

To run the examples:

  1. Run All Examples: Execute run_all_examples.py to run all examples in the repository.

    py run_all_examples.py
    
    python3 run_all_examples.py
    

    This script will sequentially run all examples listed in run_all_examples.py file, showcasing conversions to different formats, handling files in archives, retrieving document info, and listing possible conversions.

  2. Run a Specific Example: Navigate to the directory where example script is located and run it.

  3. Output Files: Most of the examples generates an output file or files, saved in the same folder where the example script is located. Also, you can find all the output files on the corresponding documentation page.

Troubleshooting

If you encounter any issues while running the examples:

  • Ensure that package is installed correctly.
  • Visit our Technical Support page for further assistance.