Aspose.Words Cloud API helps you to convert DOCX to PDF with a cloud-based file format conversion Ruby library. This article is about how to convert DOCX to PDF.
DOCX is a well-known format for Microsoft Word documents and was introduced with Microsoft Word 2007. Docx is based on open XML and Docx files can be opened with Word 2007. While, PDF is a Portable Document Format for representing documents. It is a versatile file format developed by Adobe Systems and can have any number of fonts and images. It provides an easy, reliable way to create, present document files and transfer of printer-ready output.
Do you want to convert a DOCX file to a PDF file? Many word document processing applications provide the capabilities to convert Word to Pdf file format. But this whole process requires an effort to install an application as well as licensing cost. But why to pay for the whole product licensing when you only need to perform one single operation. Furthermore, bulk conversion operations cannot be performed with such market available software. In all such cases, Aspose.Words Cloud API comes into action to perform an easy and quick file format processing.
Aspose.Words DOCX to PDF Converter app instantly converts your DOCX files in PDF format with the help of open-source Ruby SDK. These SDKs and tools are maintained by the developers at Aspose.Words and provide the easiest way to integrate Aspose.Words Cloud API with your application. You can easily convert your DOCX files to PDF file with this free Ruby SDK tool. Aspose.Words helps you to convert DOCX Documents into PDFs instantly with high fidelity. Using the Aspose Cloud REST API it is possible to perform advanced file format processing. Moreover, you can find generated ready-to-use cURL code snippet example at the bottom of this page.
Aspose supports many options for integrating document automation into applications of several platforms and programming languages. In this article, we are going to discuss following topics in detail. Let’s Explore.
- Top Word Processing Document APIs
- How to Install Aspose.Words Ruby SDK?
- Aspose.Cloud Account Subscription Explained
- How to Convert DOCX to PDF Using Aspose.Words?
- How to Use cURL for DOC to PDF Conversion?
Top Word Processing Document APIs
Aspose.Words document converter allows you to convert your files from DOCX to PDF in high quality. Aspose.Words Cloud API supports a lot of different file formats like DOC, DOCX, DOCM, DOTX, RTF, ODT, OTT and many more. It is an exciting solution to create, manipulate and transform leading Word document formats using aspose conversion technology. You will get very accurate conversion results quickly.
You can perform all these file conversion operations in the cloud without MS Office automation or any other dependencies. In order to facilitate our customers, specific programming language SDKs were developed so that you can access the API right within your application code. In this article, our emphasis is on Aspose.Words Cloud SDK for Ruby by enabling the Ruby developers to implement Word document processing capabilities in Ruby applications quickly and easily, with zero initial cost.
How to Install Aspose.Words Ruby SDK?
In order to use Ruby SDK for communicating with the Aspose.Words Cloud REST API, we first need to install it on our system. Ruby SDK is available to download with zero initial cost as RubyGem (recommended) and from GitHub. Once you have Ruby runtime configured, please execute the following command in the terminal to perform the quick and easy installation in a Ruby application for word docx to pdf converter.
gem 'aspose_words_cloud', '~> 22.3' # or install directly gem install aspose_words_cloud
But before you proceed with the installation of Aspose.Words Cloud SDK for Ruby 2.6 or later, you need to install the following dependency packages on your system.
# Following are the runtime dependencies to setup aspose_words_cloud faraday 1.4.3 >= 1.4.1 marcel 1.0.1 >= 1.0.0 multipart-parser 0.1.1 >= 0.1.1 # Development dependencies is minitest 5.14.4 ~> 5.11, >= 5.11.3
This SDK for Ruby supports more than 20 document-related formats with full read and write access. For more details, please visit aspose cloud documentation website.
Aspose.Cloud Account Subscription Explained
After installing all dependency packages of Ruby environment, the next step is to obtain ClientID and ClientSecret details to make calls to the Aspose.Words cloud APIs for Doc to Pdf conversion. There are two options to consume the REST APIs directly via some rest client like cURL or using cloud SDKs. So, the first step is to create an account by navigating Aspose.Cloud dashboard. If you have Google or Microsoft account then simply click Google or Microsoft button to Sign Up. Otherwise click Sign Up link to create new account by providing the required information.
After sign into the cloud space dashboard and click the Applications tab in the left sidebar. Now scroll down, click Create New Application button as shown in the image below.
Now create your new application by selecting your default storage as shown in the image below. You can also configure third-party storage to upload your data files by following how to configure 3rd party cloud storage guide.
Now, scroll down towards the Client Credentials section to copy Client Id and Client Secret as shown in the image below.
These Client Credentials will be used to make API Calls to the Aspose.Words cloud APIs for DOCX to PDF converter. Next, we will see how to convert a Word to PDF by using Aspose.Words cloud SDK for Ruby.
How to Convert DOCX to PDF Using Aspose.Words?
- The first step is to create ruby variables holding ClientID and ClientSecret copied from the aspose cloud dashboard.
- At second, create AsposeWordsCloud configuration and pass ClientID, ClientSecret values.
- Third step is to create an instance of WordsAPI
- Next, upload source DOCX file to cloud storage using UploadFileRequest() method
- Now, create an object of ConvertDocumentRequest() which takes input DOCX name, resultant format as arguments
- Finally, initiate DOCX to PDF conversion process with the convert_document() method.
# Load the gem, please go to https://github.com/aspose-words-cloud/aspose-words-cloud-ruby require 'aspose_words_cloud' # How to convert Word to PDF programmatically. # Get AppKey and AppSID credentials from https://dashboard.aspose.cloud/applications @app_client_id = "######-####-####-####-#########" @app_client_secret = "##########################" # Associate Configuration properties with WordsApi AsposeWordsCloud.configure do |config| config.client_data['ClientId'] = @app_client_id config.client_data['ClientSecret'] = @app_client_secret end # Create an instance of WordsApi @words_api = WordsAPI.new # Input DOCX file @fileName = "mysample.docx" # Final file format @format = "pdf" # Upload the original document to your selected cloud storage @words_api.upload_file UploadFileRequest.new(File.new(@fileName, 'rb'), @fileName, nil) # Define document conversion parameters initialize(document, format, out_path, file_name_field_value, storage, fonts_location) @request = ConvertDocumentRequest.new(File.new(@fileName, 'rb'), @format, nil, nil, nil, nil) # Initiate DOCX to PDF conversion process @result = @words_api.convert_document(@request) puts @result.to_s.inspect # Print result response in console puts("Document successfully converted to pdf") # End document converting example
As a result mysample.pdf will be saved at the root of project folder.
How to Use cURL for DOC to PDF Conversion?
Now let’s examine how to convert a word document to pdf using cURL. cURL command line tool is used to access REST APIs to and from a server. Since Aspose.Words Cloud APIs are developed as per REST principles, so we can use these Cloud APIs to do the conversion operations. To perform conversion, we will generate JSON Web Token (JWT) based on ClientID and ClientSecret retrieved from Aspose.Cloud dashboard. Please execute the command in the terminal to generate the JWT token like below.
curl -v "https://api.aspose.cloud/connect/token" \ -X POST \ -d "grant_type=client_credentials&client_id=######-####-####-####-######&client_secret=#########################" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Accept: application/json"
Next, add the JWT token in below command to convert the DOC file to PDF format and the input DOCX file should be available on cloud storage. Then outPath parameter shows the location for the resultant PDF document and the format is the format of the resultant pdf file. GetDocumentWithFormat API is for document conversion and doc-to-pdf.doc file is rendered to PDF format successfully. You can check saved file with doc-to-pdf.pdf name in cloud storage.
curl -X GET "https://api.aspose.cloud/v4.0/words/test_multi_pages.docx?format=pdf&outPath=doc-to-pdf.pdf" \ -H "accept: application/octet-stream" \ -H "Authorization: <PASTE HERE JWT Token>"
In the above article, we have explained the steps for how to convert DOCX file to PDF file using Aspose.Words Cloud SDK for Ruby. Aspose Cloud SDKs are open-source software and the complete code of Aspose.Words cloud SDK for Ruby is available on GitHub.
We also recommend visiting following related links: