PDF to DOC – Convert PDF to DOC in C#

PDF to DOC

PDF files are widely used for data and information sharing because they preserve document fidelity when viewing on any platform including Desktop or Mobile. Owing to this wide acceptability and compatibility, PDF files are widely popular in organizations, Government institutes, universities, etc. However, the file may contain outdated or incorrect information, or you simply want to add a few more lines of text to it. So, it turns out that PDF editing is not an easy task to achieve. Therefore, you need to download and install any PDF editing software, which can be quite a laborious process. On top of that, most of the PDF software is not free, so this can make the task look even more daunting.

A viable solution is to transform the PDF file into a Word document (DOC). The Word document is widely accepted and any business document, including presentations, proposals, company reports, plans, and budgets are created in MS Word (DOC) format. When using any application, you have to perform the conversion one by one but bulk conversion is not possible. Therefore, a programmatic solution is always viable.

Word processing API

Aspose.Words Cloud is a programming API offering the capabilities to open, create, edit, merge, split, compare and convert MS Word files to other Supported File Formats. It is developed as per REST architecture so it can be accessed on any platform i.e. Windows, macOS, Linux, Android, iOS, etc. Create your dream conversion application with few code lines. In order to further facilitate the customers, we have developed programming language-specific Cloud SDKs. The SDK is the quickest way to speed up the development. An SDK takes care of low-level details and lets you focus on your project tasks.

Therefore, Aspose.Words Cloud SDK for .NET is specifically developed for .NET customers. Simply integrate our Cloud API into your applications to get a full-featured Word API that allows you to work, manipulate and integrate documents into your C#, ASP.NET, and all other .NET apps including web, mobile, desktop, gaming, IoT, cloud, and microservices.

Installation

In order to get started with Cloud SDK, the first step is to install it over the system. It is available on NuGet and GitHub. Please execute the following command in the terminal window to perform the installation for NuGet:

nuget install Aspose.Words-Cloud

If you are using Visual Studio, then the package can also be installed using Package Manager Console. Please execute the following command:

 PM> Install-Package Aspose.Words-Cloud
Aspose.Words Cloud
Image 1:- Aspose.Words NuGet package installed.

NuGet Package Manager – Visual Studio

Another easiest approach is to install the SDK via NuGet Package Manager within Visual Studio IDE.

  1. Open the Solution Explorer.
  2. Expand the project and Right-click Packages folder within your solution.
  3. Select Manage NuGet Packages… option
  4. Click on the Browse tab and search for “Aspose.Words-Cloud
  5. Click on the Aspose.Words-Cloud package, select the appropriate version in the right-tab and click Add Package button
Image 2:- Aspose.Words Package in NuGet Package Manager.

Cloud subscription

In order to ensure the data security and integrity of files stored on cloud storage, and only authorized persons can access it. So the users who upload their protected/personal files to cloud storage must only have access to those files. Furthermore, the subscription on cloud storage is free and you can perform up to 150 free document processing operations. So once you are satisfied with the capabilities of API, you may consider opting for a license subscription which can be as low as $0.005 / API call. For further details, please visit Pricing.

Now proceed with account creation by visiting Aspose.Cloud dashboard. No credit card or other payment details are required. If you have GitHub or Google account, simply Sign Up or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials
Image 3:- Client Credentials at Aspose.Cloud dashboard.

PDF to DOC in C#

Please follow the steps given below to perform the conversion:

  • First of all, please create an instance of Configuration while passing Client ID and Client Secret credentials as arguments
  • Secondly, create an object of WordsApi while passing Configuration instance as an argument
  • Thirdly, read the PDF file using File.OpenRead object
  • Now create an instance of UploadFileRequest file and use UploadFile(…) method to upload PDF to Cloud storage
  • Penultimate, create an instance of GetDocumentWithFormatRequest while passing input file name, resultant format and output file name as argument
  • Finally, call the GetDocumentWithFormat(..) method to perform conversion and save output to Cloud storage

The sample files used in the above example can be downloaded from awesome_table_in_pdf.pdf and converted.doc.

Convert PDF to DOC using cURL

You can use the 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. But, before performing the file conversion operation, please try creating a JWT access token based on your client credentials. Please execute the following cURL command to generate the JWT access token.

 curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=4db2f826-bf9c-42e7-8b2a-8cbca2d15553&client_secret=d757548a9f2558c39c2feebdf85b4c44" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Now we need to execute the following command to upload the PDF file to Cloud storage:

curl -X PUT "https://api.aspose.cloud/v4.0/words/storage/file/awesome_table_in_pdf.pdf" \
-H  "accept: application/json" \
-H  "Authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"fileContent":{}}

Finally, call the following command to convert PDF file available in Cloud storage to DOC format:

curl -X GET "https://api.aspose.cloud/v4.0/words/awesome_table_in_pdf.pdf?format=DOC&outPath=converted.doc" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

Conclusion

In this article, we have highlighted the features of Aspose.Words Cloud for Word document processing. Specifically, we have discussed the details on how we can perform the conversion of PDF files to DOC using a C# .NET code snippet as well as a cURL command. Nevertheless, Aspose.Words Cloud SDK for .NET which is a wrapper around Aspose.Words Cloud is developed under the MIT license, so the complete code snippet can be downloaded from GitHub. If you encounter any issues while using the API, please feel free to contact us via the Free Product support forum.

Related articles

We recommend visiting the following links to learn more about