Notepad is a word processing program, which allows you to create quick notes in a TXT file. Windows Notepad is a simple text editor created by the Microsoft corporation. Converting text to PDF file gives it more versatility, as the final document can be viewed on any system. To perform TXT to PDF conversion programmatically, this article covers how to convert TXT files to PDF using REST API in Ruby.
The following topics shall be covered in this tutorial:
- The API for Converting TXT Documents to PDF Files
- How to Convert TXT to PDF using REST API in Ruby
- TXT to PDF Conversion using Advanced Options in Ruby
The API for Converting TXT Documents to PDF Files
To begin to convert TXT to PDF, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. Our Cloud APIs allows you to convert your documents and images of any supported file format to any format you need. You can easily convert between more than 50 types of documents and images such as Word, PowerPoint, Excel, PDF, HTML, CAD, raster images, etc.
You can install GroupDocs.Conversion TXT to pdf library free into your Ruby application. Hit the below command in rails terminal for converting TEXT to PDF using gem:
gem 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:
How to Convert TXT to PDF using REST API in Ruby
You can convert your TXT format to PDF format by following the simple steps mentioned below: Firstly, upload the text document to the cloud storage for TXT2pdf conversion. As a result, the uploaded text file will be available in the files section of your dashboard on the cloud. Now, you can convert TXT document to PDF programmatically by following the steps given below:
- Create an instance of ConvertApi
- Create an instance of the ConvertSettings
- Set the TXT file path and output fileformat as “pdf”
- Create an instance of the TXTLoadOptions
- Set the encoding to shift_jis
- Assign load options settings
- Provide the output file path “text-to-pdf”
- Create ConvertDocumentRequest with ConvertSettings
- Finally, call the convert_document() method with ConvertDocumentRequest
The following code example shows how to convert from TXT file to PDF document using REST API:
The above code sample will save the text2pdf file format on the cloud. You can download it right away in your browser.
TXT to PDF Conversion using Advanced Options in Ruby
You can also convert TXT to PDF documents using advance options programmatically by following the steps given below:
- Create an instance of ConvertApi
- Create an instance of the ConvertSettings
- Set the TXT file path and output fileformat as “pdf”
- Create an instance of the TXTLoadOptions
- Set the encoding and trailing_spaces_options values
- Create an instance of the PdfConvertOptions
- Set various convertOptions center_window, from_page, margin_top etc.
- Assign load options settings and convert options settings
- Set the output file path “text-to-pdf”
- Create ConvertDocumentRequest with ConvertSettings
- Now finally call the convert_document() method with ConvertDocumentRequest
The following code example shows how to convert TXT document to PDF document with advance settings using REST API in Ruby.
Online TXT to PDF Converter for Free
How to convert a text file (.txt) to PDF online? Convert TXT to PDF online free and in one click using our best TXT to pdf converter free. It is easy-to-use TXT to pdf converter online free. This free text to pdf converter was developed using the above convert text to pdf API. Please try the following text document to pdf converter online free.
Summing up
In this article, we have learned how to:
- convert TXT to PDF documents using ruby;
- convert txt to pdf using advance options in ruby;
You can learn more about GroupDocs.Conversion file converter API using the documentation. We also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser.
Ask a question
If you have any queries about TXT to PDF converter, please feel free to ask us on the Forum.