PDF is a document file format that contains text, data etc and is operating system independent. A TXT file is a standard text document with .TXT extension that contains plain text in the form of lines. It can be opened and edited in any text editing or word processing tool. In certain cases, you may need to convert PDF document to text file programmatically. In this article, you will learn how to convert PDF to Text file programmatically using REST API in Ruby.
The following topics shall be covered in this article:
- PDF to TEXT Conversion REST API and Ruby SDK
- Convert PDF to TEXT File using REST API in Ruby
- Convert Specific Pages of PDF to TEXT in Ruby
- Free Online TXT to PDF Converter
PDF to TEXT Conversion REST API and Ruby SDK
For converting PDF to TXT file, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. You can install it using the following command in the rails console:
gem install groupdocs_conversion_cloud
Please get your Client ID and Secret from the GroupDocs Dashboard before following the below mentioned steps. Once you have your Client ID and Client Secret, add these in the ruby application code as shown below:
Convert PDF to TEXT File using REST API in Ruby
You can convert PDF file to text file by following the simple steps as given below. Let’s learn how to convert PDF document to text file programmatically by following the steps as given below:
- Firstly, create an instance of the ConvertApi.
- Create an instance of the ConvertSettings
- Set input PDF document path and output format as “pdf”
- Create an instance of the PdfLoadOptions
- Set the password for pdf file
- Then, Provide load options settings
- Provide the output file path “pdf-to-text”
- Create ConvertDocumentRequest with ConvertSettings
- Finally, call the ConvertApi.convertDocument() method with ConvertDocumentRequest.
The following code example shows how to convert PDF document to TEXT file using REST API in Ruby:
The above sample code will save the converted TEXT file on the cloud.
Convert Specific Pages of PDF to TEXT in Ruby
You can convert specific pages of PDF document to Text file programmatically by following the steps given below:
- Firstly, create an instance of the ConvertApi.
- Next, create an instance of the ConvertSettings
- Set input PDF document path and output format as “pdf”
- Then, create an instance of the PdfLoadOptions
- Set the password for pdf file
- Create an instance of TxtConvertOptions
- Provide page numbers in a comma separated array to convert
- Then, provide loadOptions settings object
- Assign convertOptions to settings object
- Provide the output file path “pdf-to-text”
- Create ConvertDocumentRequest with ConvertSettings
- Finally, call the ConvertApi.convertDocument() method with ConvertDocumentRequest.
The following code example shows how to convert specific pages from PDF to Text using REST API in Ruby:
Free Online TXT to PDF Converter
How to convert PDF to Text file online? Convert PDF to TXT online free using our best pdf to TXT converter free. This free pdf to text converter was developed using the above convert pdf to text API.
Summing up
In this article, we have learned how to:
- how to convert pdf to text file using ruby;
- how to convert specific pages of pdf to text 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 PDF to Text converter, please feel free to ask us on the Free Support Forum.