PDF to Word Aspose provides a high fidelity API to programmatically convert PDF documents to Word format and in the opposite directions with professional quality. The combined use of Adobe and Microsoft Office technologies has a lot to offer to the end-user.
These major document formats, including DOCX , DOC , RTF , ODT and PDF , are capable of encapsulating almost any type of data including text, tables, raster and vector graphics, video, audio, and also support a wide range of formatting features.
Despite similarities, PDF and Word documents have considerable differences in the operational capabilities.
PDF documents support multilevel security options and are difficult to extract information. PDF format is the best choice when the document’s author allows others to read and print document copies only. Word document formats, in contrast, are great for collaborative development, but they aren’t always the best choice for distributing as they can be easily modified without author’s permission.
You may require to convert an immutable PDF to an editable DOCX or DOC document and it is also a fine solution if you need to extract text from a PDF file easily.
Aspose conversion engine transforms a PDF to Word-based document format, that can be naturally edited with any mainstream word processor. However, some complex formatting might appear slightly different from the original document. PDF to Word conversion supports detecting headers and footers. Sections of PDF pages containing page numbers, document names, etc. will be converted as Word’s headers and footers. These headers and footers do not affect the rest of the page layout and are not moved while the document is being edited.
Aspose PDF to Word conversion engine currently supports the following features:
Text and paragraphs
Text formatting (font, size, foreground/background, options like bold, italic, underline)
Bulleted and numbered lists (including nested lists)
Tables (bordered and non-bordered, without nested tables)
Images conversion
Semi-transparent images
Rotated images
Inline images (images that go “inside” the text, being a logical part of text paragraph)
Encrypted PDF files
Properly converts style and destination of hyperlinks, both to URLs and local files
Headers/footers detection for PDF conversion
Bookmarks
Basic vector graphics
There is a restriction on the usage of multi-column text that will be addressed in future API versions. Multi-column text is currently not supported by PDF to Word conversion API.
Usage examples with cURL and Postman
You can carry out REST API interactions using the REST Service Endpoint defines a publicly accessible programming interface and lets you run PDF to Word conversions directly from a web browser.
You can use cURL command-line tool to access Aspose.Words web services and convert PDF documents to Word format easily. The following code demonstrates how to convert PDF to DOCX with cURL. Download sample demo.pdf and output demo.docx 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/online/put/saveAs" \
-X PUT \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer ####################" \
-F Document="@Sample.docx" \
-F SaveOptionsData="{\"SaveFormat\":\"pdf\",\"FileName\":\"Sample_out.pdf\"}"
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": "SaveAsOnline_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": "saveRequest",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "Document",
"type": "file",
"src": "Sample.docx"
},
{
"key": "SaveOptionsData",
"type": "text",
"value": "{\"SaveFormat\":\"pdf\",\"FileName\":\"Sample_out.pdf\"}"
}
]
},
"url": {
"raw": "https://api.aspose.cloud/v4.0/words/online/put/saveAs",
"protocol": "https",
"host": [
"api",
"aspose",
"cloud"
],
"path": [
"v4.0",
"words",
"online",
"put",
"saveAs"
],
"query": [
]
}
},
"response": []
}
],
"variable": [
]
}
To get a JWT token use this instruction
Server Response
Copy {
"SaveResult" : {
"SourceDocument" : {
"Href" : "https://api.aspose.cloud/v4.0/words/demo.pdf" ,
"Rel" : "self" ,
"Type" : null ,
"Title" : null
},
"DestDocument" : {
"Href" : "demo.docx" ,
"Rel" : "saved" ,
"Type" : null ,
"Title" : null
},
"AdditionalItems" : [
]
},
"Code" : 200 ,
"Status" : "OK"
}
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.
The following code examples demonstrate how to convert PDF to Word programmatically using various Aspose.Words SDKs:
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')
request_save_options_data = asposewordscloud.SaveOptionsData(save_format='pdf', file_name='Sample_out.pdf')
save_request = asposewordscloud.models.requests.SaveAsOnlineRequest(document=request_document, save_options_data=request_save_options_data)
words_api.save_as_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.docx").toAbsolutePath());
SaveOptionsData requestSaveOptionsData = new SaveOptionsData();
requestSaveOptionsData.setSaveFormat("pdf");
requestSaveOptionsData.setFileName("Sample_out.pdf");
SaveAsOnlineRequest saveRequest = new SaveAsOnlineRequest(requestDocument, requestSaveOptionsData, null, null, null, null);
wordsApi.saveAsOnline(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.docx");
const requestSaveOptionsData = new model.SaveOptionsData({
saveFormat: "pdf",
fileName: "Sample_out.pdf"
})
const saveRequest = new model.SaveAsOnlineRequest({
document: requestDocument,
saveOptionsData: requestSaveOptionsData
});
wordsApi.saveAsOnline(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.docx");
var requestSaveOptionsData = new SaveOptionsData()
{
SaveFormat = "pdf",
FileName = "Sample_out.pdf"
};
var saveRequest = new SaveAsOnlineRequest(requestDocument, requestSaveOptionsData);
await wordsApi.SaveAsOnline(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\{SaveAsOnlineRequest};
use Aspose\Words\Model\{SaveOptionsData};
$clientId = '####-####-####-####-####';
$secret = '##################';
$wordsApi = new WordsApi($clientId, $secret);
$requestDocument = "Sample.docx";
$requestSaveOptionsData = new SaveOptionsData(array(
"save_format" => "pdf",
"file_name" => "Sample_out.pdf",));
$saveRequest = new SaveAsOnlineRequest(
$requestDocument, $requestSaveOptionsData, NULL, NULL, NULL, NULL);
$wordsApi->saveAsOnline($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.docx"), std::istream::binary));
auto requestSaveOptionsData = std::make_shared<aspose::words::cloud::models::SaveOptionsData>();
requestSaveOptionsData->setSaveFormat(std::make_shared<std::wstring>(L"pdf"));
requestSaveOptionsData->setFileName(std::make_shared<std::wstring>(L"Sample_out.pdf"));
std::shared_ptr<requests::SaveAsOnlineRequest> saveRequest(
new requests::SaveAsOnlineRequest(
requestDocument, requestSaveOptionsData));
wordsApi->saveAsOnline(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.docx")
requestSaveOptionsData := models.SaveOptionsData{
SaveFormat: ToStringPointer("pdf"),
FileName: ToStringPointer("Sample_out.pdf"),
}
saveRequestOptions := map[string]interface{}{}
saveRequest := &models.SaveAsOnlineRequest{
Document: requestDocument,
SaveOptionsData: &requestSaveOptionsData,
Optionals: saveRequestOptions,
}
_, _, _ = wordsApi.SaveAsOnline(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.docx')
request_save_options_data = SaveOptionsData.new({:SaveFormat => 'pdf', :FileName => 'Sample_out.pdf'})
save_request = SaveAsOnlineRequest.new(document: request_document, save_options_data: request_save_options_data)
@words_api.save_as_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.docx"))!;
let requestSaveOptionsData = SaveOptionsData()
.setFileName(fileName: "Sample_out.pdf")
.setSaveFormat(saveFormat: "pdf");
let saveRequest = SaveAsOnlineRequest(document: requestDocument, saveOptionsData: requestSaveOptionsData);
_ = try api.saveAsOnline(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.docx').readAsBytes()).buffer.asByteData();
final requestSaveOptionsData = SaveOptionsData();
requestSaveOptionsData.saveFormat = 'pdf';
requestSaveOptionsData.fileName = 'Sample_out.pdf';
final saveRequest = SaveAsOnlineRequest(requestDocument, requestSaveOptionsData);
await wordsApi.saveAsOnline(saveRequest);
See also