Simplifying files with GroupDocs.Rewriter SDK
Leave feedback
Learn more
Although you can directly call the GroupDocs.Rewriter Cloud REST API to send file and fetch the result, there is a much easier way to implement required functionality in your applications. We provide software development kits (SDKs) for all popular programming languages. They wrap up all routine operations such as establishing connections, sending API requests, and parsing responses into a few simple methods. It makes interaction with GroupDocs.Rewriter Cloud services much easier, allowing you to focus on business logic rather than technical details.
packagecom.groupdocs;// Import classes:
importcom.groupdocs.model.*;importorg.openapitools.client.api.SimplifyApi;importorg.openapitools.client.api.FileApi;importjava.io.File;publicclassDemo{publicstaticvoidmain(String[]args){// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
StringbasePath="https://api.groupdocs.cloud/v2.0/rewriter";StringcliendId="YOUR_CLIENT_ID";StringclientSecret="YOUR_CLIENT_SECRET";ApiClientdefaultClient=newApiClient(basePath,cliendId,clientSecret,null);// Upload file
FileApifileApi=newFileApi(defaultClient);StringfileName="FILE_PATH";FilefileToUpload=newFile(fileName);Stringfile_url=null;try{Stringfile_url=fileApi.fileUploadPost("FILE_FORMAT",fileToUpload);}catch(ApiExceptione){System.err.println("Exception when calling FileApi#fileUploadPost");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}// Create instance of the SimplifyApi if the file was uploaded successfully
if(file_url!=null){SimplifyApiapiInstance=newSimplifyApi(defaultClient);SimplifyFileRequestfileRequest=newSimplifyFileRequest();fileRequest.setLanguage("en");fileRequest.setFormat(SimplifySupportedFromats.PDF);fileRequest.setOutputFormat(SupportedConversionsFormats.PDF);fileRequest.setSavingMode(FileSavingMode.FILES);fileRequest.setUrl(file_url);fileRequest.setOrigin("FILE_URL");try{StatusResponseresponse=apiInstance.simplifyDocumentPost(fileRequest);Stringresponse_id=response.getId();if(!response.getStatus().toString().equals("BadRequest")){while(true){SimplifyFileResponsesimplifyResponse=apiInstance.simplifyDocumentRequestIdGet(response_id);if(simplifyResponse.getStatus().toString().equals("OK")){System.out.println(simplifyResponse);break;}try{Thread.sleep(2000);}catch(InterruptedExceptione){e.printStackTrace();}}}}catch(ApiExceptione){System.err.println("Exception when calling SimplifyApi#simplifyDocumentPost");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}}