Convert PDF to Editable Word Document using Ruby

How to Convert PDF to Editable Word Document using Ruby
How to Convert PDF to Editable Word Document using Ruby

You can easily convert any of your PDF documents into editable Word documents programmatically using GroupDocs.Conversion Cloud API. GroupDocs.Conversion will allow you to update the contents of your PDF documents using Microsoft Word. As a Ruby on Rails developer, you can convert PDF files to Word documents (DOC or DOCX) programmatically on the cloud. In this article, we will learn how to convert PDF to editable Word document using Ruby cloud REST APIs.

The following topics shall be covered in this blog tutorial:

PDF Conversion REST API and Ruby SDK

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

You can install GroupDocs.Conversion Cloud in your Ruby application using the following command in the ruby on rails application console:

gem install groupdocs_conversion_cloud

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

Convert PDF to Editable Word Documents using Ruby Cloud SDK

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

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

Upload the PDF File

First of all, upload the PDF file to the cloud storage 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. Next, convert PDF to DOCX document programmatically by following the steps mentioned below:

  • First, create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set the PDF file path and assign “docx” to the format.
  • Create an instance of the PdfLoadOptions
  • Set the required loadOptions as shown in below code.
  • Create an instance of the DocxConvertOptions
  • Set the required convertOptions as shown in below code.
  • Now set convert options and output folder path to settings object.
  • Create an instance of the ConvertDocumentRequest
  • Convert by calling the convert_document() method with convert request object as argument.

Convert PDF to DOCX using Ruby

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

Convert PDF to Editable Word using a REST API in Ruby
Convert PDF to Editable Word using a REST API in Ruby

Download the Converted DOCX File

The above code sample will save the converted DOCX file in the cloud storage. Now, you can also download it using the following code sample:

PDF to Word Conversion with Advance Options

You can also convert Word documents to PDF files in ruby with advance options by following the steps as shown below:

  • First, create an instance of the ConvertApi.
  • Now, create ConvertDocumentRequest with ConvertSettings
  • Then, set the input PDF file path and format of the resultant file as “docx”
  • Now, create an instance of the PdfLoadOptions.
  • Set password for loadOptions and other options
  • Next, create an instance of the DocxConvertOptions
  • Provide load_options and output_path settings.
  • Finally, convert PDF by calling the convert_document() method with ConvertDocumentRequest

The following code sample shows how to convert a PDF to Word document with advanced convert options. Please follow the steps mentioned earlier to upload Pdf file and then to download word file.

As a result, PDF file will be converted into Word DOCX file using advance file options in ruby application.

Try Online

How to convert PDF to Word online? Please try the following free online PDF to DOCX conversion tool, which is developed using the above API for any device with a modern browser like Chrome and Firefox.

Conclusion

In this article, we have learned how to convert PDF to Word DOCX document in ruby on the cloud. You have also learned how to convert PDF to Word document with advance options using Ruby. 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 any modern browser.

Ask a question

If you have any queries about our PDF to DOCX converter, please feel free to ask us on the Forum.

See Also

We recommend the following related link for supported document conversions: