Convert Documents Document conversion Cloud API lets you convert Word document to another format. The API request contains a document to convert and the response contains the conversion result, or if outPath parameter specified - the API saves the result to the Cloud storage and return OK status code.
You can check the quality of Aspose.Words Cloud conversion and view the results online:
The list of supported formats is provided below:
format Parameter Value
Format of the returned Presentation
bmp
Bitmap image file
doc
Word document
docm
Word Open XML Macro-Enabled Document
docx
Microsoft Word Open XML Document
dot
Word Document Template
dotm
Word Open XML Macro-Enabled Document Template
dotx
Word Open XML Document Template
emf
Enhanced Windows Metafile
epub
Open eBook File
flatopc
Flat OPC format
gif
Gif Image
html
Hypertext Markup Language File
jpeg
JPEG Image
mhtml
MIME HTML File
odt
OpenDocument Text Document
ott
OpenDocument Document Template
pcl
Printer Command Language File
pdf
Portable Document Format File
png
Portable Network Graphic
rtf
Rich Text Format File
svg
Scalable Vector Graphics File
swf
Shockwave Flash Movie(removed)
txt
Plain Text File
tiff
Tagged Image File Format
wml
Wireless Markup Language File
xps
XML Paper Specification File
The important parameters are described in the following table:
Parameter Name
Type
Query String
Description
format
string
format=jpeg
Return the document in the specified format. Valid values for this parameter are given above.
outPath
string
outPath=SomeFolder/result.jpeg
A path for saving operation results to Cloud storage.
The format can also be specified by the request Accept header.
Usage examples with cURL and Postman
You can carry out REST API interactions using cURL
and Postman
. Please read these instructions to receive a personal JWT_TOKEN
for authorization.
Download sample TableDocument.doc and output TableDocument.pdf files for testing purposes.
cURL Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -v "https://api.aspose.cloud/v4.0/words/convert?format=pdf" \
-X PUT \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer ####################" \
-F Document="@Sample.docx"
To get a JWT token use this instruction
Postman Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{
"info": {
"name": "ConvertDocument_1",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "clientSecret",
"value": "{{CLIENT_SECRET}}",
"type": "string"
},
{
"key": "clientId",
"value": "{{CLIENT_ID}}",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
},
{
"key": "client_authentication",
"value": "body",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "https://api.aspose.cloud/connect/token",
"type": "string"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "string"
},
{
"key": "tokenName",
"value": "Access Token",
"type": "string"
}
]
},
"item": [
{
"name": "convertRequest",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "Document",
"type": "file",
"src": "Sample.docx"
}
]
},
"url": {
"raw": "https://api.aspose.cloud/v4.0/words/convert?format=pdf",
"protocol": "https",
"host": [
"api",
"aspose",
"cloud"
],
"path": [
"v4.0",
"words",
"convert"
],
"query": [
{
"key": "Format",
"value": "pdf",
"description": ""
}
]
}
},
"response": []
}
],
"variable": [
]
}
To get a JWT token use this instruction
Server Response
Aspose.Words Cloud SDK Family
Using SDK is the best way to speed up the development. Our Cloud SDKs take care of low-level details and let you focus on your primary tasks.
Please check out the GitHub repository for a complete list of Aspose.Words SDKs.
Usage examples in Python, Java, C#, etc.
The following code samples show how to interact with the REST API using almost any mainstream programming language.
You can find a lot of other examples in Python , Java , C# , JavaScript , PHP , C++ , Golang , Ruby , Swift , Dart on GitHub. All codes are thoroughly tested and ready for production use.
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os
import asposewordscloud
import asposewordscloud.models.requests
from asposewordscloud.rest import ApiException
from shutil import copyfile
words_api = WordsApi(client_id = '####-####-####-####-####', client_secret = '##################')
request_document = open('Sample.docx', 'rb')
convert_request = asposewordscloud.models.requests.ConvertDocumentRequest(document=request_document, format='pdf')
words_api.convert_document(convert_request)
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.aspose.words.cloud.*;
import com.aspose.words.cloud.api.*;
import com.aspose.words.cloud.model.*;
import com.aspose.words.cloud.model.requests.*;
import com.aspose.words.cloud.model.responses.*;
import java.nio.file.Files;
import java.nio.file.Paths;
ApiClient apiClient = new ApiClient(/*clientId*/ "####-####-####-####-####", /*clientSecret*/ "##################", null);
WordsApi wordsApi = new WordsApi(apiClient);
byte[] requestDocument = Files.readAllBytes(Paths.get("Sample.docx").toAbsolutePath());
ConvertDocumentRequest convertRequest = new ConvertDocumentRequest(requestDocument, "pdf", null, null, null, null, null, null, null);
wordsApi.convertDocument(convertRequest);
Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from "fs";
const clientId = "####-####-####-####-####";
const secret = "##################";
const wordsApi = new WordsApi(clientId, secret);
const requestDocument = fs.createReadStream("Sample.docx");
const convertRequest = new model.ConvertDocumentRequest({
document: requestDocument,
format: "pdf"
});
wordsApi.convertDocument(convertRequest)
.then((convertRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of convertRequest: ", convertRequestResult);
});
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Aspose.Words.Cloud.Sdk;
using Aspose.Words.Cloud.Sdk.Model;
using Aspose.Words.Cloud.Sdk.Model.Requests;
var config = new Configuration { ClientId = "####-####-####-####-####", ClientSecret = "##################" };
var wordsApi = new WordsApi(config);
using var requestDocument = File.OpenRead("Sample.docx");
var convertRequest = new ConvertDocumentRequest(requestDocument, "pdf");
await wordsApi.ConvertDocument(convertRequest);
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php
use Aspose\Words\WordsApi;
use Aspose\Words\Model\Requests\{ConvertDocumentRequest};
$clientId = '####-####-####-####-####';
$secret = '##################';
$wordsApi = new WordsApi($clientId, $secret);
$requestDocument = "Sample.docx";
$convertRequest = new ConvertDocumentRequest(
$requestDocument, "pdf", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
$wordsApi->convertDocument($convertRequest);
C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "aspose_words_cloud.h"
using namespace aspose::words::cloud;
auto config = std::make_shared<ApiConfiguration>(/*clientId*/ L"####-####-####-####-####", /*clientSecret*/ L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);
auto requestDocument = std::shared_ptr<std::istream>(new std::ifstream(std::filesystem::path(L"Sample.docx"), std::istream::binary));
std::shared_ptr<requests::ConvertDocumentRequest> convertRequest(
new requests::ConvertDocumentRequest(
requestDocument, std::make_shared<std::wstring>(L"pdf")));
wordsApi->convertDocument(convertRequest);
Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{
"ClientId" : " ####-####-####-####-####" ,
"ClientSecret" : " ##################" ,
"BaseUrl" : " https://api.aspose.cloud"
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import (
"os"
"github.com/aspose-words-cloud/aspose-words-cloud-go/dev/api/models")
config, _ := models.NewConfiguration("config.json")
wordsApi, ctx, _ := api.CreateWordsApi(config)
requestDocument, _ := os.Open("Sample.docx")
convertRequestOptions := map[string]interface{}{}
convertRequest := &models.ConvertDocumentRequest{
Document: requestDocument,
Format: ToStringPointer("pdf"),
Optionals: convertRequestOptions,
}
_, _ = wordsApi.ConvertDocument(ctx, convertRequest)
Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aspose_words_cloud'
AsposeWordsCloud.configure do |config|
config.client_data['ClientId'] = '####-####-####-####-####'
config.client_data['ClientSecret'] = '##################'
end
@words_api = WordsAPI.new
request_document = File.open('Sample.docx')
convert_request = ConvertDocumentRequest.new(document: request_document, format: 'pdf')
@words_api.convert_document(convert_request)
Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AsposeWordsCloud
let config = Configuration ( clientId: " ####-####-####-####-#### " , clientSecret: " ################## " ) ;
let api = try WordsAPI ( configuration: config) ;
let requestDocument = InputStream ( url: URL ( string: " Sample.docx " ) ) !;
let convertRequest = ConvertDocumentRequest ( document: requestDocument, format: " pdf " ) ;
_ = try api. convertDocument ( request: convertRequest) ;
Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io';
import 'package:aspose_words_cloud/aspose_words_cloud.dart';
final clientId = "####-####-####-####-####";
final clientSecret = "##################";
final config = Configuration(clientId, clientSecret);
final wordsApi = WordsApi(config);
final requestDocument = (await File('Sample.docx').readAsBytes()).buffer.asByteData();
final convertRequest = ConvertDocumentRequest(requestDocument, 'pdf');
await wordsApi.convertDocument(convertRequest);
See also