Convert PDF to Editable Word Document using Node.js

Convert PDF to Editable Word Document using Node.js

You can easily convert any of your PDF documents into editable Word documents programmatically. This conversion will let you update the contents of your PDF documents using Microsoft Word. As a Node.js developer, you can convert PDF files to Word documents (DOC or DOCX) programmatically on the cloud. In this article, you will learn how to convert PDF to an editable Word document using a REST API in Node.js.

The following topics shall be covered in this article:

PDF Conversion REST API and Node.js SDK

For converting PDF to DOCX, I will be using the Node.js SDK of GroupDocs.Conversion Cloud API. It is a platform-independent document and image conversion solution without depending on any tool or software. It enables you to quickly and reliably convert images and documents of any supported file format to any format you need. You can easily convert between over 50 types of documents and images such as Word, PowerPoint, Excel, PDF, HTML, CAD, raster images, etc. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document conversion family members for the Cloud API.

You can install GroupDocs.Conversion Cloud to your Node.js project using the following command in the console:

npm install groupdocs-conversion-cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, please add in the code as shown below:

Convert PDF to Editable Word Document using a REST API in Node.js

You can convert your PDF document to an editable Word document programmatically on the cloud by following the simple steps given below:

  1. Upload the PDF file to the cloud
  2. Convert PDF to DOCX using Node.js
  3. Download the converted DOCX file

Upload the PDF File

Firstly, upload the PDF file to the cloud using the following code sample:

As a result, the uploaded PDF file will be available in the files section of your dashboard on the cloud.

Convert PDF to DOCX using Node.js

You can easily convert PDF to DOCX document programmatically by following the steps mentioned below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set the PDF file path
  • Assign “docx” to the format
  • Provide the output file path
  • Create ConvertDocumentRequest with ConvertSettings
  • Convert by calling the convertDocument() method with ConvertDocumentRequest

The following code example shows how to convert PDF to Word document using a REST API in Node.js.

Convert PDF to Editable Word using a REST API in Node.js
Convert PDF to Editable Word using a REST API in Node.js

Download the Converted File

The above code sample will save the converted DOCX file on the cloud. You can download it using the following code sample:

Convert Specific Pages of PDF to DOCX in Node.js

You can easily convert specific pages of a PDF document to a Word document programmatically by following the steps mentioned below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set the PDF file path
  • Assign “docx” to the format
  • Provide the output file path
  • Create an instance of the DocxConvertOptions
  • Provide specific page numbers to convert
  • Assign DocxConvertOptions to ConvertSettings
  • Create ConvertDocumentRequest with ConvertSettings
  • Convert by calling the convertDocument() method with ConvertDocumentRequest

The following code example shows how to convert specific pages of a PDF to Word document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.

The following code example shows how to convert a range of pages from a PDF document to a Word document using a REST API in Node.js.

PDF to Word Conversion without using Cloud Storage

You can convert a PDF document without using the cloud storage by passing it in the request body and receiving the output file in the API response. Please follow the steps mentioned below to convert a PDF to a DOCX without using cloud storage.

  • Create an instance of the ConvertApi
  • Read input PDF file from local path
  • Create ConvertDocumentDirectRequest
  • Provide target format and the input file path as input parameters
  • Get results by calling the convertDocumentDirect() method with ConvertDocumentDirectRequest
  • Save the output file to the local path using FileStream.writeFile() method

The following code example shows how to convert a PDF to a Word document without using cloud storage.

Try Online

Please try the following free online PDF to DOCX conversion tool, which is developed using the above API. https://products.groupdocs.app/conversion/pdf-to-docx

Conclusion

In this article, you have learned how to convert PDFs to Word documents on the cloud. You have also learned how to convert specific pages of a PDF to a Word document using Node.js. Moreover, you have learned how to convert a range of pages from a PDF to DOCX programmatically. This article also explained how to programmatically upload the PDF file on the cloud and then download the converted DOCX 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. In case of any ambiguity, please feel free to contact us on the forum.

See Also