Save the specified Range as a new document Saves the specified Range
as a new document.
Save the specified Range as a new document REST API
Server
Method
Endpoint
https://api.aspose.cloud/v4.0
PUT
/words/online/post/range/{rangeStartIdentifier}/{rangeEndIdentifier}/SaveAs
, where:
rangeStartIdentifier
(required) — the range start identifier.
rangeEndIdentifier
— the range end identifier.
You can use the following parameters in a REST request:
Parameter Name
Data Type
Required/Optional
Description
loadEncoding
string
Optional
Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.
password
string
Optional
Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don’t recommend to use the parameter to pass a plain password for direct call of API.
encryptedPassword
string
Optional
Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details.
Use $multipart/form-data
request to combine one or more properties into a single body:
Property Name
Data Type
Required/Optional
Description
document
string(binary)
Required
The document.
documentParameters
RangeDocument
Required
Parameters of a new document.
Note : to access this REST API, you need to register and get personal credentials. Use the ‘
Quick Start ’ guide to go through the procedure in a couple of minutes.
Save the specified Range as a new document usage examples
Let’s look at practical examples of using the web service. You can do this both with cURL and Postman utilities, and from your code in various programming languages: Python, Java, JavaScript, C#, PHP, C++, Go, Ruby, Swift, Dart.
How to save the specified Range as a new document with cURL or Postman
One of the easiest and fastest ways to call a REST API is to use cURL or Postman:
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/online/post/range/id0.0.0/id0.0.1/SaveAs" \
-X PUT \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer ####################" \
-F Document="@Sample.doc" \
-F DocumentParameters="{\"DocumentName\":\"NewDocument.docx\"}"
To get a JWT token use these instructions
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": "SaveAsRangeOnline",
"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": "saveRequest",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "Document",
"type": "file",
"src": "Sample.doc"
},
{
"key": "DocumentParameters",
"type": "text",
"value": "{\"DocumentName\":\"NewDocument.docx\"}"
}
]
},
"url": {
"raw": "https://api.aspose.cloud/v4.0/words/online/post/range/id0.0.0/id0.0.1/SaveAs",
"protocol": "https",
"host": [
"api",
"aspose",
"cloud"
],
"path": [
"v4.0",
"words",
"online",
"post",
"range",
"id0.0.0",
"id0.0.1",
"SaveAs"
],
"query": [
]
}
},
"response": []
}
],
"variable": [
]
}
To get a JWT token use these instructions
How to save the specified Range as a new document in Python, Java, C#, C++, JavaScript and other programming languages
Using SDK is the quickest way to speed up the development. Please take a look at the provided code examples to quickly call this web service from your favourite programming language:
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.doc', 'rb')
request_document_parameters = asposewordscloud.RangeDocument(document_name='NewDocument.docx')
save_request = asposewordscloud.models.requests.SaveAsRangeOnlineRequest(document=request_document, range_start_identifier='id0.0.0', document_parameters=request_document_parameters, range_end_identifier='id0.0.1')
words_api.save_as_range_online(save_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.doc").toAbsolutePath());
RangeDocument requestDocumentParameters = new RangeDocument();
requestDocumentParameters.setDocumentName("NewDocument.docx");
SaveAsRangeOnlineRequest saveRequest = new SaveAsRangeOnlineRequest(requestDocument, "id0.0.0", requestDocumentParameters, "id0.0.1", null, null, null);
wordsApi.saveAsRangeOnline(saveRequest);
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.doc");
const requestDocumentParameters = new model.RangeDocument({
documentName: "NewDocument.docx"
})
const saveRequest = new model.SaveAsRangeOnlineRequest({
document: requestDocument,
rangeStartIdentifier: "id0.0.0",
documentParameters: requestDocumentParameters,
rangeEndIdentifier: "id0.0.1"
});
wordsApi.saveAsRangeOnline(saveRequest)
.then((saveRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of saveRequest: ", saveRequestResult);
});
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.doc");
var requestDocumentParameters = new RangeDocument()
{
DocumentName = "NewDocument.docx"
};
var saveRequest = new SaveAsRangeOnlineRequest(requestDocument, "id0.0.0", requestDocumentParameters, rangeEndIdentifier: "id0.0.1");
await wordsApi.SaveAsRangeOnline(saveRequest);
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\{SaveAsRangeOnlineRequest};
use Aspose\Words\Model\{RangeDocument};
$clientId = '####-####-####-####-####';
$secret = '##################';
$wordsApi = new WordsApi($clientId, $secret);
$requestDocument = "Sample.doc";
$requestDocumentParameters = new RangeDocument(array(
"document_name" => "NewDocument.docx",));
$saveRequest = new SaveAsRangeOnlineRequest(
$requestDocument, "id0.0.0", $requestDocumentParameters, "id0.0.1", NULL, NULL, NULL);
$wordsApi->saveAsRangeOnline($saveRequest);
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.doc"), std::istream::binary));
auto requestDocumentParameters = std::make_shared<aspose::words::cloud::models::RangeDocument>();
requestDocumentParameters->setDocumentName(std::make_shared<std::wstring>(L"NewDocument.docx"));
std::shared_ptr<requests::SaveAsRangeOnlineRequest> saveRequest(
new requests::SaveAsRangeOnlineRequest(
requestDocument, std::make_shared<std::wstring>(L"id0.0.0"), requestDocumentParameters, std::make_shared<std::wstring>(L"id0.0.1")));
wordsApi->saveAsRangeOnline(saveRequest);
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.doc")
requestDocumentParameters := models.RangeDocument{
DocumentName: ToStringPointer("NewDocument.docx"),
}
saveRequestOptions := map[string]interface{}{"rangeEndIdentifier": "id0.0.1",}
saveRequest := &models.SaveAsRangeOnlineRequest{
Document: requestDocument,
RangeStartIdentifier: ToStringPointer("id0.0.0"),
DocumentParameters: &requestDocumentParameters,
Optionals: saveRequestOptions,
}
_, _, _ = wordsApi.SaveAsRangeOnline(ctx, saveRequest)
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.doc')
request_document_parameters = RangeDocument.new({:DocumentName => 'NewDocument.docx'})
save_request = SaveAsRangeOnlineRequest.new(document: request_document, range_start_identifier: 'id0.0.0', document_parameters: request_document_parameters, range_end_identifier: 'id0.0.1')
@words_api.save_as_range_online(save_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.doc"))!;
let requestDocumentParameters = RangeDocument()
.setDocumentName(documentName: "NewDocument.docx");
let saveRequest = SaveAsRangeOnlineRequest(document: requestDocument, rangeStartIdentifier: "id0.0.0", documentParameters: requestDocumentParameters, rangeEndIdentifier: "id0.0.1");
_ = try api.saveAsRangeOnline(request: saveRequest);
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.doc').readAsBytes()).buffer.asByteData();
final requestDocumentParameters = RangeDocument();
requestDocumentParameters.documentName = 'NewDocument.docx';
final saveRequest = SaveAsRangeOnlineRequest(requestDocument, 'id0.0.0', requestDocumentParameters, rangeEndIdentifier: 'id0.0.1');
await wordsApi.saveAsRangeOnline(saveRequest);
See Also
GitHub repository — explore Aspose.Words Cloud SDK Family. These software libraries take care of all low-level document-processing details.