Convert PDF to Editable DOCX with Python
Tags: python, pdftodocx, documentconversion, restapi
Published: 2019-11-07 12:56:18

While working with document conversion feature, you came across a requirement to convert PDF to DOCX. I would like to introduce GroupDocs.Conversion Cloud SDK for Python for the purpose. It can also convert all popular industry standard documents from one format to another without depending on any third-party tool or software.

All you need to convert PDF to DOCX in Python follow these steps:

* Before we begin with coding, sign up with [groupdocs.cloud](https://docs.groupdocs.cloud/display/gdtotalcloud/Creating+and+Managing+Account) to get your APP SID and APP Key.

* Install groupdocs-conversion-cloud package from [pypi](https://pypi.org/project/groupdocs-conversion-cloud/) with the following command.
```>pip install groupdocs-conversion-cloud```

* Open your favorite editor and copy paste following code into the script file
  1. Import the GroupDocs.Conversion Cloud Python package
  2. Initialize the API
  3. Upload source PDF document to GroupDocs default storage
  4. Convert the PDF document to editable DOCX

```python
# Import module
import groupdocs_conversion_cloud

# Get your app_sid and app_key at https://dashboard.groupdocs.cloud (free registration is required).
app_sid = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Create instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)
file_api = groupdocs_conversion_cloud.FileApi.from_keys(app_sid, app_key)

try:

        #upload soruce file to storage
        filename = 'Sample.pdf'
        remote_name = 'Sample.pdf'
        output_name= 'sample.docx'
        strformat='docx'

        request_upload = groupdocs_conversion_cloud.UploadFileRequest(remote_name,filename)
        response_upload = file_api.upload_file(request_upload)
        #Convert PDF to Word document
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path =remote_name
        settings.format = strformat
        settings.output_path = output_name
        
        loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
        loadOptions.hide_pdf_annotations = True
        loadOptions.remove_embedded_files = False
        loadOptions.flatten_all_fields = True

        settings.load_options = loadOptions

        convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()
        convertOptions.from_page = 1
        convertOptions.pages_count = 1
            
        settings.convert_options = convertOptions
 .               
        request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
        response = convert_api.convert_document(request)

        print("Document converted successfully: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
        print("Exception when calling get_supported_conversion_types: {0}".format(e.message))
```

* And that’s it. PDF document is converted to DOCX and API response includes the URL of the resultant document. [Read more](https://blog.groupdocs.cloud/2019/11/06/convert-pdf-to-editable-word-document-with-python-sdk/).

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/8flv5h8uv7a2sbc0dvy3.PNG)