Word to PDF

Convert PDF to Word or Word to PDF using Ruby SDK

Many word document processing applications provide the capabilities to process MS Word & OpenOffice formats and also, enable you to render the output to other file formats including PDF. But the bulk conversion operations cannot be performed with such software and in all such circumstances, a programmatic solution is a viable approach. In this article, we are going to discuss the conversion of DOC to PDF and PDF to DOC using Ruby SDK.

DOC to PDF Conversion API

Aspose.Words Cloud is an exciting solution to create, manipulate and transform leading Word document formats. Now in order to implement the Word to PDF conversion routine in the Ruby application, we are going to install Aspose.Words Cloud SDK for Ruby The SDK is available for download as Ruby GEM and GitHub. So once you have Ruby runtime configured, please execute the following command on the terminal to perform the installation.

gem install aspose_words_cloud

But before you proceed with the installation of Aspose.Words Cloud SDK for Ruby, you need to install the following dependencies.

Runtime dependencies(3)

Development dependencies (1)

After the installation, we need to create a free account by visiting Aspose.Cloud dashboard. Sign up with your GitHub or Google account or click the Create a new Account button. Notice your Client Credentials as we are going to use them in the following sections.

Convert DOC to PDF in Ruby

Please follow the instructions given below to perform Word to PDF conversion using Ruby language.

  • The first step is to create variables holding your ClientID and ClientSecret details from the dashboard
  • Secondly, create an instance of configure from AsposeWordsCloud and pass ClientID and ClientSecret values
  • Thirdly, create an instance of WordsAPI
  • Now upload source DOCX file to cloud storage using UploadFileRequest(…) method
  • The next step is to create an object of ConvertDocumentRequest(..) which takes the input DOCX name, the resultant format as arguments
  • Finally, call the convert_document(..) method to perform the conversion operation

PDF to DOC in Ruby

PDF is one of the widely used document formats, capable of encapsulating text, tables, raster/vector graphics, video, and audio data. It also maintains document fidelity on any platform, therefore, we receive lots of documents in PDF format. But in order to edit them, you need specific applications and in this section, we are going to develop our PDF to Word conversion application in Ruby.

  • First, we need to create an object of WordsAPI where we provide ClientID and ClientSecret details
  • Secondly, create an instance of SaveAsRequest which takes SaveOptionsData object specifying target format and output file name as arguments
  • Finally, call save_as(..) method and pass the SaveAsRequest object to perform the conversion

Use cURL command for DOC to PDF conversion

The cURL commands are an exciting way to access REST APIs on any platform. Since Aspose.Words Cloud is developed as per REST principles, so we can use them to perform the conversion operation. However, before proceeding, we need to first generate JSON Web Token (JWT) based on your ClientID and ClientSecret details retrieved from Aspose.Cloud dashboard. Please execute the following command in the terminal to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once a new JWT token is generated, use the following command to convert the DOC file to PDF format. The name parameter indicates the input DOCX file already available on Cloud storage, the format parameter denotes the format of the resultant file and outPath shows the location for the resultant PDF document. The conversion is performed using GetDocumentWithFormat API and in the example given below, test_multi_pages.docx file is rendered to PDF format and saved with the name MyConverted.pdf.

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

PDF to DOC conversion using the cURL command

The conversion of PDF to DOC/DOCX and other supported Word document formats can be performed using the cURL command. For this purpose, we need to use ConvertDocument API.

curl -X PUT "https://api.aspose.cloud/v4.0/words/converted.pdf/saveAs" \
-H  "accept: application/json" \
-H  "Authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{\"SaveFormat\":\"docx\",\"FileName\":\"output.docx\",\"AllowEmbeddingPostScriptFonts\":true,\"ZipOutput\":false,\"UpdateLastSavedTimeProperty\":true,\"UpdateSdtContent\":true,\"UpdateFields\":true,\"Dml3DEffectsRenderingMode\":\"Basic\",\"UpdateCreatedTimeProperty\":true,\"UpdateLastPrintedProperty\":true}"


In the above article, we have discussed the exciting and convenient way of DOCX file to PDF conversion and PDF to DOC/DOCX file conversion using Aspose.Words Cloud SDK for Ruby. Please note that all our Cloud SDKs are Opensource and similarly, the complete code of Aspose.Words cloud SDK for Ruby is available on GitHub.

We also recommend visiting the following links for related details on