pythonpdfepubaspose

Download output of aspose API PDF to EPUB conversion in python


I have been using the cloud below and it has produced no errors yet there is also no outputted epub file. Am I missing something? Can someone please explain?

import asposewordscloud
from asposewordscloud.apis.words_api import WordsApi

words_api = WordsApi(client_id = ‘SECRET, client_secret = ‘SECRET’)
doc = open(‘Input.pdf’, 'rb')
request = asposewordscloud.models.requests.ConvertDocumentRequest(document=doc, format='epub')
convert = words_api.convert_document(request)

I tried the above code and was expected a sign or something to show me that it has actually worked.


Solution

  • Please note that the convert_document API method returns an output file in response, so you need to save the output from the response as follows:

    Python convert PDF to EPUB

    # 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='xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
    client_secret='xxxxxxxxxxxxxxxxxxxxxxxxxx'
    
    words_api = asposewordscloud.WordsApi(client_id,client_secret)
    inputFileName = 'C:/Temp/02_pages.pdf'
    outputFileName = 'C:/Temp/output.epub'
    
    #Convert PDF to EPUB
    request = asposewordscloud.models.requests.ConvertDocumentRequest(document=open(inputFileName, 'rb'), format='epub')
    result = words_api.convert_document(request)
    
    #Save output to local drive
    open(outputFileName,'wb').write(result)
    #copyfile(result, outputFileName)
    #print("Result {}".format(result))
    
    

    P.S: I am a developer evangelist at aspose.cloud.