Convert document without storage

This example demonstrates how to convert document without using cloud storage. Use this method to directly convert any document, using conversion options.

Method parameters:

NameTypeDescriptionComment
formatstringRequested conversion formatRequired.
FilebinaryInput file to convertForm data, Required
fromPageintegerPage start conversion fromDefault value : 1
pagesCountintegerNumber of pages to convertDefault value : 0 (all pages)
loadOptionsLoadOptionsInput file loading optionsForm data
convertOptionsConvertOptionsConversion optionsForm 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"
Code 200
<binary file>

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-samples
string MyClientSecret = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
string MyClientId = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
  
var configuration = new Configuration(MyClientId, MyClientSecret);
  
// Create necessary API instances
var apiInstance = new ConvertApi(configuration);

// Prepare request
var fileStream = File.Open("..\\..\\..\\Resources\\WordProcessing\\password-protected.docx", FileMode.Open);
var loadOptions = new DocxLoadOptions();
loadOptions.Format = "docx";
loadOptions.Password = "password";
var request = new ConvertDocumentDirectRequest("pdf", fileStream, null, null, loadOptions);

// Convert to specified format
var response = 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
String MyClientSecret = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
String MyClientId = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
  
Configuration configuration = new Configuration(MyClientId, MyClientSecret);
  
// Create API instance
ConvertApi apiInstance = new ConvertApi(configuration);

File file = new File("examples\\src\\main\\resources\\WordProcessing\\password-protected.docx");
DocxLoadOptions loadOptions = new DocxLoadOptions();
loadOptions.setFormat("docx");
loadOptions.setPassword("password");

ConvertDocumentDirectRequest request = new ConvertDocumentDirectRequest("pdf", file, 1, 0, loadOptions, null); // all pages

File result = 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
use GroupDocs\Conversion\Model;
use GroupDocs\Conversion\Model\Requests;

$ClientId = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
$ClientSecret = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
  
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid($ClientId);
$configuration->setAppKey($ClientSecret);

$apiInstance = new GroupDocs\Conversion\ConvertApi($configuration);

// Prepare request
$filePath = dirname(realpath(__DIR__)) . '\Resources\WordProcessing\password-protected.docx';
$loadOptions = new Model\DocxLoadOptions();
$loadOptions->setFormat("docx");
$loadOptions->setPassword("password");        
$request = new Requests\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);

let file = fs.readFileSync('./Resources/WordProcessing/password-protected.docx');
let loadOptions = new conversion_cloud.DocxLoadOptions();
loadOptions.format = "docx";
loadOptions.password = "password";
let request = new conversion_cloud.ConvertDocumentDirectRequest("pdf", file, undefined, undefined, loadOptions);

let result = await convertApi.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-samples
import 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 instances
apiInstance = groupdocs_conversion_cloud.ConvertApi.from_keys(Common.client_id, Common.client_secret)

# Prepare request
load_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)

# Convert
result = 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-samples
require '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 instances
apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys($client_id, $client_secret)

# Prepare request
file = File.open("Resources\\WordProcessing\\password-protected.docx", "r")
load_options = GroupDocsConversionCloud::DocxLoadOptions.new
load_options.format = "docx"
load_options.password = "password"
request = GroupDocsConversionCloud::ConvertDocumentDirectRequest.new("pdf", file, nil, nil, load_options)

# Convert
result = 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
package convert

import (
 "fmt"
 "os"

 "github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-go-samples/config"
)

func ConvertToPdfDirect() {

 path := "./Resources/WordProcessing/four-pages.docx"
 localFile, err := os.Open(path)
 if err != nil {
  fmt.Printf("Failed to open file %s: %v\n", path, err)
  return
 }
 defer localFile.Close()

 result, _, err := config.Client.ConvertApi.ConvertDocumentDirect(config.Ctx, "pdf", localFile, nil)

 if err != nil {
  fmt.Printf("ConvertToPdfDirect error: %v\n", err)
  return
 }

 fi, _ := result.Stat()

 fmt.Printf("Document converted successfully: %v\n", fi.Size())
}