This example demonstrates how to convert word processing document into pdf document asyncronously without using cloud storage. There are steps that usage of GroupDocs.Conversion Cloud consists of:
Start convert operation and get operation ID
Get operation status
Get operation result (converted document)
Resource URI
HTTP PUT ~/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 PUT \
-H "Content-Type: application/json"\
-H "Accept: application/json"\
-H "Authorization: Bearer <jwt token>"--data-binary "@path/to/file"
"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);varfileStream=File.Open("four-pages.docx",FileMode.Open);varrequest=newStartConvertRequest("pdf",fileStream);// Convert to specified formatvaroperationId=apiInstance.StartConvert(request);Console.WriteLine("Operation ID: "+operationId);while(true){Thread.Sleep(1000);varresult=apiInstance.GetOperationStatus(newGetOperationStatusRequest(operationId));if(result.Status==OperationResult.StatusEnum.Finished){varresponse=apiInstance.GetOperationResult(newGetOperationResultRequest(operationId));Console.WriteLine("Document converted successfully: "+response.Length);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);Filefile=newFile("four-pages.docx");StringoperationId=apiInstance.startConvert(newStartConvertRequest("pdf",file,1,0));System.out.println("Operation ID: "+operationId);while(true){Thread.sleep(1000);OperationResultresult=apiInstance.getOperationStatus(newGetOperationStatusRequest(operationId));if(result.getStatus()==StatusEnum.FINISHED){FileconvertedFile=apiInstance.getOperationResult(newGetOperationResultRequest(operationId));System.out.println("Document converted: "+convertedFile.length());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);letfile=fs.readFileSync('four-pages.docx');letrequest=newconversion_cloud.StartConvertRequest("pdf",file);letoperationId=awaitasyncApi.startConvert(request);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){varresponse=awaitasyncApi.getOperationResult(newconversion_cloud.GetOperationResultRequest(operationId));console.log("Document converted successfully: "+response.length);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 request
$filePath=dirname(realpath(__DIR__)).'four-pages.docx';$request=newRequests\StartConvertRequest("pdf",$filePath);// Convert
$operationId=$apiInstance->startConvert($request);$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){$result=$apiInstance->getOperationResult(newRequests\GetOperationResultRequest($operationId));echo"Document converted successfully: ".$result->getSize();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 requestrequest=groupdocs_conversion_cloud.StartConvertRequest("pdf","four-pages.docx")# Convertoperation_id=apiInstance.start_convert(request)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"):response=apiInstance.get_operation_result(groupdocs_conversion_cloud.GetOperationResultRequest(operation_id))print("Document converted: "+response)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 requestfile=File.open("four-pages.docx","r")request=GroupDocsConversionCloud::StartConvertRequest.new("pdf",file)# Convertoperation_id=apiInstance.start_convert(request)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"response=apiInstance.get_operation_result(GroupDocsConversionCloud::GetOperationResultRequest.new(operation_id))puts("Document converted: "+(response.length).to_s)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""os""time""github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go-samples/config""github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go/models")funcConvertToPdfDirectAsync(){path:="./Resources/WordProcessing/four-pages.docx"localFile,err:=os.Open(path)iferr!=nil{fmt.Printf("Failed to open file %s: %v\n",path,err)return}deferlocalFile.Close()operationId,_,err:=config.Client.AsyncApi.StartConvert(config.Ctx,"pdf",localFile,nil)iferr!=nil{fmt.Printf("ConvertToPdfDirectAsync 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("ConvertToPdfDirectAsync error: %v\n",err)return}ifresult.Status==models.StatusEnumFinished{result,_,_:=config.Client.AsyncApi.GetOperationResult(config.Ctx,operationId)fi,_:=result.Stat()fmt.Printf("Document converted successfully: %v\n",fi.Size())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.