This example demonstrates how to convert word processing document into pdf document asyncronously. There are steps that usage of GroupDocs.Conversion Cloud consists of:
Upload input document into cloud storage
Start convert operation and get operation ID
Get operation status
After get “Finished” status, download converted document from storage
Steps 1 and 4 are storage operations, please refer to this for usage details.
Resource URI
HTTP POST ~/conversion/async
Swagger UI lets you call this REST API directly from the browser.
cURL example
// First get JSON Web Token
// Please get your Client Id and Client Secret from https://dashboard.groupdocs.cloud/applications. Kindly place Client Id in "client_id" and Client Secret in "client_secret" argument.
curl -v "https://api.groupdocs.cloud/connect/token"\
-X POST \
-d "grant_type#client_credentials&client_id#xxxx&client_secret#xxxx"\
-H "Content-Type: application/x-www-form-urlencoded"\
-H "Accept: application/json"// cURL example to convert document
curl -v "https://api.groupdocs.cloud/v2.0/conversion/async"\
-X POST \
-H "Content-Type: application/json"\
-H "Accept: application/json"\
-H "Authorization: Bearer <jwt token>"-d "{
'FilePath': 'WordProcessing/four-pages.docx',
'Format': 'pdf',
'OutputPath': 'Output'
}"
"ecbfa56b-3545-4620-86a0-4c500c8ac38e"
SDK examples
Our API is completely independent of your operating system, database system or development language. You can use any language and platform that supports HTTP to interact with our API. However, manually writing client code can be difficult, error-prone and time-consuming. Therefore, we have provided and support API SDKs in many development languages in order to make it easier to integrate with us.
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet-samplesstringMyClientSecret="";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloudstringMyClientId="";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloudvarconfiguration=newConfiguration(MyClientId,MyClientSecret);// Create necessary API instancesvarapiInstance=newAsyncApi(configuration);// Prepare convert settingsvarsettings=newConvertSettings{FilePath="WordProcessing/four-pages.docx",Format="pdf",OutputPath="converted"};// Convert to specified formatvaroperationId=apiInstance.StartConvertAndSave(newStartConvertAndSaveRequest(settings));Console.WriteLine("Operation ID: "+operationId);while(true){Thread.Sleep(1000);varresult=apiInstance.GetOperationStatus(newGetOperationStatusRequest(operationId));if(result.Status==OperationResult.StatusEnum.Finished){Console.WriteLine("Document converted successfully: "+result.Result[0].Url);break;}elseif(result.Status==OperationResult.StatusEnum.Failed){Console.WriteLine("Document converted failed: "+result.Error);break;}else{Console.WriteLine("Operation status: "+result.Status);}}
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-java-samples
StringMyClientSecret="";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
StringMyClientId="";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
Configurationconfiguration=newConfiguration(MyClientId,MyClientSecret);// Create API instance
AsyncApiapiInstance=newAsyncApi(configuration);// Prepare convert settings
ConvertSettingssettings=newConvertSettings();settings.setFilePath("WordProcessing/four-pages.docx");settings.setFormat("pdf");settings.setOutputPath("converted");StringoperationId=apiInstance.startConvertAndSave(newStartConvertAndSaveRequest(settings));System.out.println("Operation ID: "+operationId);while(true){Thread.sleep(1000);OperationResultresult=apiInstance.getOperationStatus(newGetOperationStatusRequest(operationId));if(result.getStatus()==StatusEnum.FINISHED){System.out.println("Document converted successfully: "+result.getResult().get(0).getUrl());break;}elseif(result.getStatus()==StatusEnum.FAILED){System.out.println("Document converted failed: "+result.getError());break;}else{System.out.println("Operation status: "+result.getStatus());}}
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-node-samples
global.merger_cloud=require("groupdocs-conversion-cloud");global.clientId="XXXX-XXXX-XXXX-XXXX";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
global.clientSecret="XXXXXXXXXXXXXXXX";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
global.asyncApi=conversion_cloud.AsyncApi.fromKeys(clientId,clientSecret);letsettings=newconversion_cloud.ConvertSettings();settings.filePath="WordProcessing/four-pages.docx";settings.format="pdf";letoperationId=awaitasyncApi.startConvertAndSave(newconversion_cloud.StartConvertAndSaveRequest(settings));console.log("Operaion ID: "+operationId);while(true){await(asyncfunction(){constsleep=ms=>newPromise(resolve=>setTimeout(resolve,ms))awaitsleep(1000)})()letresult=awaitasyncApi.getOperationStatus(newconversion_cloud.GetOperationStatusRequest(operationId));if(result.status==conversion_cloud.OperationResult.StatusEnum.Finished){console.log("Document converted successfully: "+result.result[0].url);break;}elseif(result.status==conversion_cloud.OperationResult.StatusEnum.Failed){console.log("Document converted failed: "+result.error);break;}else{console.log("Operation status: "+result.status);}}
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-php-samples
useGroupDocs\Conversion\Model;useGroupDocs\Conversion\Model\Requests;$ClientId="";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
$ClientSecret="";// Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
$configuration=newGroupDocs\Conversion\Configuration();$configuration->setAppSid($ClientId);$configuration->setAppKey($ClientSecret);$apiInstance=newGroupDocs\Conversion\AsyncApi($configuration);// Prepare convert settings
$settings=newModel\ConvertSettings();$settings->setFilePath("WordProcessing/four-pages.docx");$settings->setFormat("pdf");$settings->setOutputPath("converted");// Convert
$operationId=$apiInstance->startConvertAndSave(newRequests\StartConvertAndSaveRequest($settings));$operationId=trim($operationId,'"');echo"Operaion ID: ".$operationId;echo"\n";while(true){sleep(1);$result=$apiInstance->getOperationStatus(newRequests\GetOperationStatusRequest($operationId));if($result->getStatus()==Model\OperationResult::STATUS_FINISHED){echo"Document converted successfully: ".$result->getResult()[0]->getUrl();echo"\n";break;}elseif($result->getStatus()==Model\OperationResult::STATUS_FAILED){echo"Document converted failed: ".$result->getError();echo"\n";break;}else{echo"Operation status: ".$result.getStatus();}}
# For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-python-samplesimportgroupdocs_conversion_cloudclient_id="XXXX-XXXX-XXXX-XXXX"=GetClientIdandClientSecretfromhttps://dashboard.groupdocs.cloudclient_secret="XXXXXXXXXXXXXXXX"=GetClientIdandClientSecretfromhttps://dashboard.groupdocs.cloud# Create necessary API instancesapiInstance=groupdocs_conversion_cloud.AsyncApi.from_keys(Common.client_id,Common.client_secret)# Prepare convert settingssettings=groupdocs_conversion_cloud.ConvertSettings()settings.file_path="WordProcessing/four-pages.docx"settings.format="pdf"settings.output_path="converted"# Convertoperation_id=apiInstance.start_convert_and_save(groupdocs_conversion_cloud.StartConvertAndSaveRequest(settings))print("Operaion ID: "+operation_id)while(True):time.sleep(1)result=apiInstance.get_operation_status(groupdocs_conversion_cloud.GetOperationStatusRequest(operation_id))if(result.status=="Finished"):print("Document converted: "+result.result[0].url)breakelif(result.status=="Failed"):print("Operation failed: "+result.error)breakelse:print("Operation status: "+result.status)
# For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-ruby-samplesrequire'groupdocs_conversion_cloud'$client_id="XXXX-XXXX-XXXX-XXXX"=GetClientIdandClientSecretfromhttps://dashboard.groupdocs.cloud$client_secret="XXXXXXXXXXXXXXXX"=GetClientIdandClientSecretfromhttps://dashboard.groupdocs.cloud# Create necessary API instancesapiInstance=GroupDocsConversionCloud::AsyncApi.from_keys($client_id,$client_secret)# Prepare convert settingssettings=GroupDocsConversionCloud::ConvertSettings.newsettings.file_path="WordProcessing/four-pages.docx"settings.format="pdf"settings.output_path="converted"# Convertoperation_id=apiInstance.start_convert_and_save(GroupDocsConversionCloud::StartConvertAndSaveRequest.new(settings))operation_id=operation_id.delete_prefix('"').delete_suffix('"')puts("Operation ID: "+operation_id)whiletruesleep(1)result=apiInstance.get_operation_status(GroupDocsConversionCloud::GetOperationStatusRequest.new(operation_id))ifresult.status=="Finished"puts("Document converted: "+result.result[0].url)breakelsifresult.status=="Failed"puts("Operation failed: "+result.error)breakelseputs("Operation status: "+result.status)endend
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go-samples
packageasyncimport("fmt""time""github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go-samples/config""github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go/models")funcConvertToPdfAsync(){settings:=models.ConvertSettings{Format:"pdf",FilePath:"WordProcessing/password-protected.docx",OutputPath:"converted",LoadOptions:&models.WordProcessingLoadOptions{Password:"password",},ConvertOptions:&models.PdfConvertOptions{CenterWindow:true,CompressImages:false,DisplayDocTitle:true,Dpi:1024,FitWindow:false,FromPage:1,Grayscale:false,ImageQuality:100,Linearize:false,MarginTop:5,MarginLeft:5,Password:"password",UnembedFonts:true,RemoveUnusedStreams:true,RemoveUnusedObjects:true,RemovePdfaCompliance:false,},}operationId,_,err:=config.Client.AsyncApi.StartConvertAndSave(config.Ctx,settings)iferr!=nil{fmt.Printf("ConvertToPdfAsync error: %v\n",err)return}fmt.Printf("Operation ID: %v\n",operationId)for{time.Sleep(1*time.Second)result,_,err:=config.Client.AsyncApi.GetOperationStatus(config.Ctx,operationId)iferr!=nil{fmt.Printf("ConvertToPdfAsync error: %v\n",err)return}ifresult.Status==models.StatusEnumFinished{fmt.Printf("Document converted successfully: %v\n",result.Result[0].Url)break}ifresult.Status==models.StatusEnumFailed{fmt.Printf("Document converted failed: %v\n",result.Error_)break}fmt.Printf("Operation status: %v\n",result.Status)}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.