
Convert PDF to Word in C# .NET using REST API
PDF (Portable Document Format) is one of the most popular file formats to protect and secure documents online. Word (.doc, .docx) is one of the most commonly used word-processing document formats. It allows you to create, edit, view, and share your documents quickly and easily using the Word processing application. In various cases, you want to convert PDF file to Word file to edit and update documents. So, in this article, I will show you how to convert PDF to Word in C# .NET using REST API.
The following topics shall be covered in this article:
- File and Document Conversion API – .NET SDK Installation
- Convert PDF to Editable Word Document Programmatically in C#
- Convert PDF to Word DOCX in C# using Advanced Options
- How to Convert Range of Pages from PDF to DOCX File in C#
- How to Convert Specific Pages of PDF to Word Document in C#
File and Document Conversion API – .NET SDK Installation
In order to convert PDF to Word Doc, I will be using the .NET SDK of GroupDocs.Conversion Cloud API. It is a fast secure, feature-rich, and reliable file format conversion platform. C# .NET API can convert back and forth between over 50 types of files, including all formats like PDF, HTML, CAD, raster images, and many more. It also allows you to convert and extract format-specific information from a wide list of supported source document formats into any supported document format. Additionally, it provides a flexible set of settings to customize the conversion process. Currently, it supports Java, PHP, Ruby, Python, CSharp,and Node.js SDKs as its document conversion family members
You can download and install it to your VS Code project from the NuGet Package manager or add it using the following command in the Package console:
dotnet add package GroupDocs.Conversion-Cloud --version 22.10.0
Next, get the Client ID and Client Secret from the dashboard before you start following the steps and available code snippets. Add your Client ID and Client Secret in the code as demonstrated below:
//Get clientId & clientSecret from https://dashboard.groupdocs.cloud (free registration is required). | |
string clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; | |
string clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
string myStorage = "test-internal-storage"; | |
var configuration = new Configuration(clientId, clientSecret); | |
configuration.ApiBaseUrl = "https://api.groupdocs.cloud"; |
Convert PDF to Editable Word Document Programmatically in C#
Converting a PDF to a Word document can be useful when you want to reuse or edit the content of the PDF, or when you want to make it easier to collaborate on the document. You can convert PDF to Word file in CSharp using REST API by following the simple steps mentioned below:
- Upload the PDF document to the Cloud
- Convert PDF file to Word DOCX using REST API
- Download the converted file
Upload the PDF File
Firstly, upload the PDF document to the Cloud using any of the following methods:
- Using the dashboard
- Upload source file using Upload File API from the browser
- Upload programmatically using the code example given below:
using System; | |
using GroupDocs.Conversion.Cloud.Sdk.Api; | |
using GroupDocs.Conversion.Cloud.Sdk.Client; | |
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; | |
using System.IO; | |
namespace GroupDocs.Conversion.CSharp | |
{ | |
// Upload Sample File | |
class Upload_File | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// initialize api | |
var fileApi = new FileApi(configuration); | |
// open file | |
var fileStream = File.Open(@"H:\groupdocs-cloud-data\input-sample-file.pdf", FileMode.Open); | |
// create file upload request | |
var request = new UploadFileRequest("csharp-testing/input-sample-file.pdf", fileStream, myStorage); | |
// upload file | |
var response = fileApi.UploadFile(request); | |
Console.WriteLine("PDF File Upload Process Completed: " + response.Uploaded.Count.ToString()); | |
fileStream.Close(); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception when calling GroupDocs FileApi: " + e.Message); | |
} | |
} | |
} | |
} |
As the result, the PDF file will be uploaded to the cloud storage.
Convert PDF to Word File Online
This section demonstrates how to convert PDF files to Word files programmatically in C# using REST API. Follow the steps mentioned below:
- Firstly, create an instance of the ConvertApi
- Secondly, create an instance of the ConvertSettings
- Next, provide the input PDF file path
- Then, assign “docx” to the format
- Create an instance of the PdfLoadOptions
- Provide the input file password
- Now, set the output file path
- Create ConvertDocumentRequest with ConvertSettings
- Finally, convert by calling the convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert PDF to Word DOCX in C# using REST API:
// How to Convert PDF to Word File using C# REST API | |
using System; | |
using GroupDocs.Conversion.Cloud.Sdk.Api; | |
using GroupDocs.Conversion.Cloud.Sdk.Client; | |
using GroupDocs.Conversion.Cloud.Sdk.Model; | |
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; | |
namespace GroupDocs.Conversion.CSharp | |
{ | |
// Change PDF file to Word DOCX in C# | |
class Convert_PDF_to_Word | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// Create necessary API instances | |
var apiInstance = new ConvertApi(configuration); | |
// Prepare convert settings | |
var settings = new ConvertSettings | |
{ | |
FilePath = "csharp-testing/input-sample-file.pdf", | |
Format = "docx", | |
LoadOptions = new PdfLoadOptions() { Password = "password" }, | |
OutputPath = "csharp-testing/output-sample-file.docx" | |
}; | |
// Convert to specified format | |
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings)); | |
Console.WriteLine("Successfully converted PDF file to Word document in C#: " + response[0].Url); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception when calling GroupDocs ConvertApi: " + e.Message); | |
} | |
} | |
} | |
} |

Convert PDF to Word DOCX
Download the Converted File
The above code sample will save the converted Word file on the cloud. You can download it using the following code sample:
// How to Download converted Word file in C# | |
using System; | |
using GroupDocs.Conversion.Cloud.Sdk.Api; | |
using GroupDocs.Conversion.Cloud.Sdk.Client; | |
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; | |
namespace GroupDocs.Conversion.CSharp | |
{ | |
// Download Output File | |
class Download_File | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// initialize api | |
var fileApi = new FileApi(configuration); | |
// create download file request | |
var downloadRequest = new DownloadFileRequest("csharp-testing/output-sample-file.docx", myStorage); | |
// download file | |
Stream downloadResponse = fileApi.DownloadFile(downloadRequest); | |
// save file in working directory | |
using (var fileStream = System.IO.File.Create("H:\\groupdocs-cloud-data\\output-sample-file.docx")) | |
{ | |
downloadResponse.Seek(0, SeekOrigin.Begin); | |
downloadResponse.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception when calling GroupDocs FileApi: " + e.Message); | |
} | |
} | |
} | |
} |
Convert PDF to Word DOCX in C# using Advanced Options
Next, convert PDF file to Word document using additional settings by following the steps mentioned below:
- Firstly, create an instance of the ConvertApi
- Secondly, create an instance of the ConvertSettings
- Next, provide the PDF file path as input
- Then, assign “docx” to the format
- Now, create an instance of the PdfLoadOptions
- Provide a password for the input file
- Create an instance of the DocxConvertOptions
- Optionally set various convert parameters like Password, Zoom, Dpi, Width, Height, etc.
- Provide the output file path
- Create ConvertDocumentRequest with ConvertSettings
- Lastly, convert by calling the convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert PDF file to Word document with advanced convert options:
// How to transform PDF to Word using Advanced Options | |
using System; | |
using GroupDocs.Conversion.Cloud.Sdk.Api; | |
using GroupDocs.Conversion.Cloud.Sdk.Client; | |
using GroupDocs.Conversion.Cloud.Sdk.Model; | |
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; | |
namespace GroupDocs.Conversion.CSharp | |
{ | |
// Convert PDF to Word DOCX using Advanced Options | |
class Convert_PDF_to_Word_Advanced_Options | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// Create necessary API instances | |
var apiInstance = new ConvertApi(configuration); | |
// Prepare convert settings | |
var settings = new ConvertSettings | |
{ | |
FilePath = "csharp-testing/input-sample-file.pdf", | |
Format = "docx", | |
LoadOptions = new PdfLoadOptions { Password = "password" }, | |
ConvertOptions = new DocxConvertOptions() { Password = "password", Zoom = 100, Dpi = 300, Width = 100, Height = 100 }, | |
OutputPath = "csharp-testing/output-sample-file.docx" | |
}; | |
// Convert to specified format | |
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings)); | |
Console.WriteLine("Successfully converted PDF file to Word file format: " + response[0].Url); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception when calling GroupDocs ConvertApi: " + e.Message); | |
} | |
} | |
} | |
} |
How to Convert Range of Pages from PDF to DOCX File in C#
This section is about how to convert selected range of pages from PDF file to Word. So, you have to provide a range of pages as demonstrated in the code snippet below. Convert a range of pages from a PDF file to Word document programmatically by following the steps given below:
- Create an instance of the ConvertApi
- Next, create an instance of the ConvertSettings
- Provide the PDF file path as input
- Now, assign “docx” to the format
- Create an instance of the PdfLoadOptions
- Provide a password for the input file
- Create an instance of the DocxConvertOptions
- Now, set pages range parameters FromPage and PagesCount with the document password.
- Next, provide the output file path
- Create ConvertDocumentRequest with ConvertSettings
- Finally, convert by calling the convertDocument() method with ConvertDocumentRequest
The following code sample shows how to convert a range of pages from PDF to Word DOCX using REST API in C#:
// How to Convert Range of Pages from PDF to Word DOC in CSharp | |
using System; | |
using System.Collections.Generic; | |
using GroupDocs.Conversion.Cloud.Sdk.Api; | |
using GroupDocs.Conversion.Cloud.Sdk.Client; | |
using GroupDocs.Conversion.Cloud.Sdk.Model; | |
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; | |
namespace GroupDocs.Conversion.CSharp | |
{ | |
// Convert Selected Pages from PDF to Word in CSharp | |
class Convert_Range_of_Pages_from_PDF_to_Word | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// Create necessary API instances | |
var apiInstance = new ConvertApi(configuration); | |
// Prepare convert settings | |
var settings = new ConvertSettings | |
{ | |
FilePath = "csharp-testing/input-sample-file.pdf", | |
Format = "docx", | |
LoadOptions = new PdfLoadOptions { Password = "password" }, | |
ConvertOptions = new DocxConvertOptions | |
{ | |
FromPage = 1, | |
PagesCount = 2, | |
Password = "password" | |
}, | |
OutputPath = "csharp-testing/output-sample-file.docx" | |
}; | |
// Convert to specified format | |
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings)); | |
Console.WriteLine("Successfully converted Selected Pages from PDF to Word file in CSharp: " + response[0].Url); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception when calling GroupDocs ConvertApi: " + e.Message); | |
} | |
} | |
} | |
} |
Please follow the steps mentioned earlier to upload and download a file.
How to Convert Specific Pages of PDF to Word Document in C#
In this section, you can convert specific pages of PDF file to Word format programmatically by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Provide the PDF file path as input
- Now, assign “docx” to the format
- Create an instance of the PdfLoadOptions
- Provide a password for the input file
- Create an instance of the DocxConvertOptions
- Now, set the page collection array with the document password.
- Provide the output file path
- Create ConvertDocumentRequest with ConvertSettings
- Finally, convert by calling the convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert specific pages of PDF file to Word document using REST API in C#:
// How to Convert Specific Pages from PDF File to Word Document in CSharp | |
using System; | |
using System.Collections.Generic; | |
using GroupDocs.Conversion.Cloud.Sdk.Api; | |
using GroupDocs.Conversion.Cloud.Sdk.Client; | |
using GroupDocs.Conversion.Cloud.Sdk.Model; | |
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; | |
namespace GroupDocs.Conversion.CSharp | |
{ | |
// Convert Specific Pages of PDF to Word using CSharp | |
class Convert_Specific_Pages_of_PDF_to_Word | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// Create necessary API instances | |
var apiInstance = new ConvertApi(configuration); | |
// Prepare convert settings | |
var settings = new ConvertSettings | |
{ | |
FilePath = "csharp-testing/input-sample-file.pdf", | |
Format = "docx", | |
LoadOptions = new PdfLoadOptions { Password = "password" }, | |
ConvertOptions = new PdfConvertOptions | |
{ | |
Password = "password", | |
Pages = new List<int?> {1, 2} // Page numbers starts from 1 | |
}, | |
OutputPath = "csharp-testing/output-sample-file.docx" | |
}; | |
// Convert to specified format | |
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings)); | |
Console.WriteLine("Successfully converted specific pages of PDF file to Word file format: " + response[0].Url); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception when calling GroupDocs ConvertApi: " + e.Message); | |
} | |
} | |
} | |
} |
Please follow the steps mentioned earlier to upload and download a file.
Online PDF to Word Converter Free
How to convert PDF to Word online? Please try the following free online PDF to Word converter without changing the format, which is developed using the above API.
Summing up
In this article, you have learned:
- how to convert PDF to Word document in C# using REST API;
- convert selected pages from PDF file to Word DOC in C# using REST API;
- programmatically convert specific pages of PDF to DOCX format in C#;
- programmatically upload the PDF file and download the converted Word file from the cloud;
Additionally, we advise you to refer to our Getting Started guide. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.
Finally, groupdocs.cloud is writing new blog articles on online file converters between multiple file formats. So, please stay in touch for regular updates.
Ask a question
For any queries/discussions about PDF to Word conversion, feel free to visit our forum.
FAQs
How do I convert PDF to Word DOC programmatically?
Please follow this link to learn the C# code snippet for how to convert PDF file to Word document quickly.
How to install PDF to Word converter API?
Install free download C# library to download, process, and convert PDF to Word DOCX format programmatically.
Can I convert PDF to Word for free?
Yes, you can convert PDF to DOC using an online PDF to Word editable converter for free.
What is the best PDF to DOCX Converter?
PDF to Document converter online is the best free PDF to DOCX converter online.
See Also
We recommend you visit the following articles to learn about:
- Convert Word to Markdown and Markdown to Word in Python
- Convert Markdown to PDF and PDF to Markdown in Python
- How to Convert EXCEL to JSON and JSON to EXCEL in Python
- How to Convert PDF to Editable Word Document using Node.js
- Convert Word Documents to PDF using REST API in Python
- How to Convert PDF to Excel in Python using REST API
- Convert CSV to JSON and JSON to CSV in Python
- Convert PowerPoint PPT/PPTX to JPG/JPEG Images in Python
- Programmatically Convert HTML to PDF using REST API in Python
- Programmatically Convert Excel to CSV using REST API in Python