This example demonstrates how to convert document without using cloud storage. Use this method to directly convert any document, using conversion options.
Method parameters:
Name
Type
Description
Comment
format
string
Requested conversion format
Required.
File
binary
Input file to convert
Form data, Required
fromPage
integer
Page start conversion from
Default value : 1
pagesCount
integer
Number of pages to convert
Default value : 0 (all pages)
loadOptions
LoadOptions
Input file loading options
Form data
convertOptions
ConvertOptions
Conversion options
Form data
Resource URI
HTTP PUT ~/conversion
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/conversion"\
-X PUT \
-H "Content-Type: multipart/form-data"\
-H "Accept: application/json"\
-H "Authorization: Bearer <jwt token>"--data-binary "@path/to/file"
Code200<binaryfile>
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=newConvertApi(configuration);// Prepare requestvarfileStream=File.Open("..\\..\\..\\Resources\\WordProcessing\\password-protected.docx",FileMode.Open);varloadOptions=newDocxLoadOptions();loadOptions.Format="docx";loadOptions.Password="password";varrequest=newConvertDocumentDirectRequest("pdf",fileStream,null,null,loadOptions);// Convert to specified formatvarresponse=apiInstance.ConvertDocumentDirect(request);Console.WriteLine("Document converted successfully: "+response.Length);
// 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
ConvertApiapiInstance=newConvertApi(configuration);Filefile=newFile("examples\\src\\main\\resources\\WordProcessing\\password-protected.docx");DocxLoadOptionsloadOptions=newDocxLoadOptions();loadOptions.setFormat("docx");loadOptions.setPassword("password");ConvertDocumentDirectRequestrequest=newConvertDocumentDirectRequest("pdf",file,1,0,loadOptions,null);// all pages
Fileresult=apiInstance.convertDocumentDirect(request);System.out.println("Document converted: "+result.length());
// 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\ConvertApi($configuration);// Prepare request
$filePath=dirname(realpath(__DIR__)).'\Resources\WordProcessing\password-protected.docx';$loadOptions=newModel\DocxLoadOptions();$loadOptions->setFormat("docx");$loadOptions->setPassword("password");$request=newRequests\ConvertDocumentDirectRequest("pdf",$filePath,null,null,$loadOptions);// Convert
$result=$apiInstance->convertDocumentDirect($request);// Done
echo"Document converted: ".$result->getSize();
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-node-samples
global.conversion_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.convertApi=conversion_cloud.ConvertApi.fromKeys(clientId,clientSecret);letfile=fs.readFileSync('./Resources/WordProcessing/password-protected.docx');letloadOptions=newconversion_cloud.DocxLoadOptions();loadOptions.format="docx";loadOptions.password="password";letrequest=newconversion_cloud.ConvertDocumentDirectRequest("pdf",file,undefined,undefined,loadOptions);letresult=awaitconvertApi.convertDocumentDirect(request);console.log("Document converted: "+result.length);
# 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"# Get ClientId and ClientSecret from https://dashboard.groupdocs.cloudclient_secret="XXXXXXXXXXXXXXXX"# Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud# Create necessary API instancesapiInstance=groupdocs_conversion_cloud.ConvertApi.from_keys(Common.client_id,Common.client_secret)# Prepare requestload_options=groupdocs_conversion_cloud.DocxLoadOptions()load_options.format="docx"load_options.password="password"request=groupdocs_conversion_cloud.ConvertDocumentDirectRequest("pdf","Resources\\WordProcessing\\password-protected.docx",None,None,load_options)# Convertresult=apiInstance.convert_document_direct(request)print("Document converted: "+result)
# 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"# Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud$client_secret="XXXXXXXXXXXXXXXX"# Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud# Create necessary API instancesapiInstance=GroupDocsConversionCloud::ConvertApi.from_keys($client_id,$client_secret)# Prepare requestfile=File.open("Resources\\WordProcessing\\password-protected.docx","r")load_options=GroupDocsConversionCloud::DocxLoadOptions.newload_options.format="docx"load_options.password="password"request=GroupDocsConversionCloud::ConvertDocumentDirectRequest.new("pdf",file,nil,nil,load_options)# Convertresult=apiInstance.convert_document_direct(request)puts("Document converted: "+(result.length).to_s)
// For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go-samples
packageconvertimport("fmt""os""github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go-samples/config")funcConvertToPdfDirect(){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()result,_,err:=config.Client.ConvertApi.ConvertDocumentDirect(config.Ctx,"pdf",localFile,nil)iferr!=nil{fmt.Printf("ConvertToPdfDirect error: %v\n",err)return}fi,_:=result.Stat()fmt.Printf("Document converted successfully: %v\n",fi.Size())}
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.