Convert PDF to Word in C# .NET using REST API

Convert PDF to Word in C# .NET using REST API
Convert PDF to Word in C# .NET using REST API

PDF (Portable Document Format) is one of the most popular file format to protect and secure documents online. Word (.doc, .docx) is one of the most commonly used word processing document format. It allows you to create, edit, view, and share your documents quickly and easily using 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

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 JavaPHPRubyPython, 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 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:

Convert PDF to Editable Word Document Programmatically in C#

You can convert Word file to PDF 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:

As the result, PDF file will be uploaded to the Cloud Storage

Convert PDF to Word File Online

This sections demonstrates how to convert PDF file to Word file to programmatically in C# file using REST API. Follow the steps mentioned below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Provide the input PDF file path
  • Assign “docx” to the format
  • Create an instance of the PdfLoadOptions
  • Provide the input file password
  • 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 online without losing formatting
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:

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:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings 
  • Provide the PDF file path as input
  • Assign “docx” to format
  • Create an instance of the PdfLoadOptions
  • Provide password for the input file
  • Create an instance of the DocxConvertOptions
  • Optionally set various convert parameters like as Password, Zoom, Dpi, Width, Height, etc.
  • 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 PDF file to Word document with advanced convert options:

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
  • Create an instance of the ConvertSettings 
  • Provide the PDF file path as input
  • Assign “docx” to format
  • Create an instance of the PdfLoadOptions
  • Provide password for the input file
  • Create an instance of the DocxConvertOptions
  • Now, set pages range parameters FromPage and PagesCount with document password.
  • 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#:

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
  • Assign “docx” to format
  • Create an instance of the PdfLoadOptions
  • Provide password for the input file
  • Create an instance of the DocxConvertOptions
  • Now, set pages collection array with 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#:

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 format, which is developed using the above API.

Conclusion

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;

You can learn more about GroupDocs.Conversion Cloud API using the documentation. 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 converter 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 online pdf to word editable converter 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