PDF to Word

Convert PDF to Word online

The PDF (Portable Document Format) files are widely popular due to their capabilities of ensuring document fidelity when viewed over any platform. Another aspect of their popularity is that these files can be opened in most modern browsers like Chrome, Safari, and Firefox can easily display them. However, in order to edit/update the existing PDF files, you need to have a PDF processing application, so the conversion of PDF to Word (DOC/DOCX, etc) can be a viable solution.

PDF to Word Conversion API

Aspose.Words Cloud SDK for Java provides you the capabilities to create, edit and render MS Word files to other supported formats. So the first step is to install the SDK which is available for download from Maven | GitHub. Now please add the following dependencies to your pom.xml file.

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://repository.aspose.cloud/repo/</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.aspose</groupId>
         <artifactId>aspose-words-cloud</artifactId>
        <version>22.5.0</version>
</dependency>

PDF to DOC using Java

Given below are the steps to load and convert PDF to DOC format using Java code snippet:

  • First of all, we need to specify clientID and clientSecret details
  • Secondly, create an object of ApiClient class where we pass ClientID and ClientSecret as arguments to the constructor. The third argument is baseUrl and by default, it points to https://api.aspose.cloud/
  • Thirdly, create an object of WordsApi class that accepts the ApiClient object as an argument to the constructor
  • Now we need to create an instance of SaveOptionsData class
  • Specify output file format details using SaveOptionsData.saveFormat(…) method
  • The name of the resultant file is specified using SaveOptionsData.fileName(…) method
  • Penultimate, we need to create an object of SaveAsRequest class where we provide an input file name and SaveOptionsData as arguments
  • Finally, call the wordsApi.saveAs(…) method where we provide SaveAsRequest instance as argument and conversion operation is initiated

The sample files used in the above examples can be downloaded from:

Convert PDF to Word using cURL Commands

Out Cloud APIs are based on REST architecture, so they can easily be accessed through the cURL commands. Now first we need to generate a JWT access token based on client credentials specified over Aspose.Cloud dashboard. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=c235e685-1aab-4cda-a95b-54afd63eb87f&client_secret=b8da4ee37494f2ef8da3c727f3a0acb9" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

For more information, please visit How to Obtain JWT token using a Client ID and Client Secret key.

Now that we have the JWT token, please execute the following cURL command to convert PDF to Word.

curl -v "https://api.aspose.cloud/v4.0/words/demo.pdf/saveAs" \
-X PUT \
-d "{'SaveFormat':'docx', 'FileName': 'Converted.docx'}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer <jwt token>"

Conclusion

In this article, we have learned the steps for converting PDF to Word using Java code snippets as well as through cURL commands. Nevertheless, our Cloud SDKs are open source, so a complete source code can be downloaded from GitHub. We also recommend visiting product Documentation for details regarding other exciting features being offered by the API.

We highly recommend visiting the following links to learn more about