We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

How To Convert DOCX to PDF Without Word Installed in Python and Download Output?


I am using Aspose.Words Cloud SDK for Python for file conversion, and I can see it in the cloud storage.
How can I download the file, or even directly read the file with Python?


You can use DownloadFile API to download files from cloud storage and here is Aspose.Words Cloud SDK for Python sample code for reference.

remoteFolder = 'Temp'
localFolder = 'C:/Temp'
remoteFileName= 'revisions.docx'

#download file from storage
request_download=asposewordscloud.models.requests.DownloadFileRequest(remoteFolder + '/' + remoteFileName)
response_download = words_api.download_file(request_download)
copyfile(response_download, localFolder + '/' +"output.docx")
1 Like

Thank you. It works, and the copyfile function is imported from shutil.

1 Like

@tilal.ahmad Thank you again. I have one more question:

How to use the DownloadFile API with Python? I don’t know how to construct the “Authorization”, the server always response [401 Authorization token is invalid or expired. ].


Please find the complete sample code to convert DOCX to PDF without Word installed in Python and download output file from cloud storage using Aspose.Words Cloud API. Hopefully, it will help you to accomplish the task.

However, if you still face the issue then please share your sample code along with the credentials. Please share the credentials via a private message. For private message, click on my user icon and opt the message tab with the required information. Kindly remove “RE:” from the title as well. We will investigate the issue and will update you.

Steps to Convert DOCX or DOC to PDF Online Python Without Word

  • Signup with aspose.cloud to get credentials for free trial
  • Install Aspose.Words Cloud SDK for Python from PIP
  • Create script file and import asposewordscloud API
  • Initiate API with credentials
  • Upload input file to Cloud storage using ‘upload_file’ API method
  • Convert DOCX to PDF with save_as API method
  • Finally download output PDF from Cloud storage to local drive

Sample Python Code to Convert DOCX to PDF Online Without Word

# For complete examples and data files, please go to https://github.com/aspose-words-cloud/aspose-words-cloud-python
# Import module
import asposewordscloud
import asposewordscloud.models.requests
from shutil import copyfile

# Please get your Client ID and Secret from https://dashboard.aspose.cloud.
client_id = 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'
client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

# Initiate API
words_api = asposewordscloud.WordsApi(client_id,client_secret)

inputFileName = 'C:/Temp/02_pages.docx'
remoteFileName = 'DocumentSaveAs.docx'
outputFileName = 'DocumentSaveAs.pdf'
localFolder = 'C:/Temp'

#upload input file to storage
request_upload = asposewordscloud.models.requests.UploadFileRequest(open(inputFileName,'rb'),remoteFileName)
response_upload = words_api.upload_file(request_upload)

#Convert DOCX to PDF and save to storage
save_options = asposewordscloud.SaveOptionsData(save_format='pdf', file_name=outputFileName)
request_conversion = asposewordscloud.models.requests.SaveAsRequest(remoteFileName, save_options)
response_conversion = words_api.save_as(request_conversion)

#download file
response_download = words_api.download_file(request_download)
copyfile(response_download, localFolder + '/' + outputFileName)