How to Convert PDF to Word Document with Python

Tilal Ahmad Sana
Nov 7 · 2 min read

In this article, I will show you how you can convert PDF to editable Word document in Python with GroupDocs.Conversion Cloud SDK for Python easily and reliably.

GroupDocs.Conversion Cloud is a platform independent document conversion REST API without any third party tool/software dependency. It provides a wide range of SDKs for different programming languages that allows you to incorporate GroupDocs.Conversion Cloud services in your favorite programming language quickly and easily.

Steps to Convert PDF to DOCX

First thing first, sign up with groupdocs.cloud to get App Sid and App Key to authenticate your REST API calls.

Install GroupDocs.Conversion Cloud SDK for Python form pypi with the following command.

>pip install groupdocs-conversion-cloud

Open your favorite editor and copy paste following code into the script file.

# 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 = loadOptionsconvertOptions = 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))

Run the code, it will convert the source PDF document to DOCX.

That’s it. For more details read on.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade