Document Conversion Library for Ruby

The ConvertAPI Ruby library provides you with the file conversion and document management capabilities. With support for hundreds of file types, from PDFs and Office documents to images, you can seamlessly convert and manipulate your documents using simple, intuitive methods.

Ruby Gem GitHub

Integrate within minutes

ConvertAPI library for Ruby is designed to streamline even the most complex workflows, the library’s flexible parameters and straightforward configuration help you reduce development overhead, improve efficiency, and deliver high-quality results with minimal effort.

It is easy to start converting documents using Ruby in a few simple steps:

1

Sign up for a free account

Sign up for free and receive 250 conversions to try and evaluate our service. You will receive a free trial with no credit card required upon registration!

2

Set up the conversion online

On your account dashboard you will access an intuitive UI tool that allows you to set up the conversion, adjust the parameters, and try the conversion online with zero code.

3

Copy auto-generated code snippet

Once you have set up the conversion parameters and are happy with the conversion results, you will receive an auto-generated Ruby code snippet with your custom parameters!

Get started now

Enterprise-Grade Document Processing

Document management toolkit for Ruby

With a simple integration in Ruby, you can convert documents not only to PDF, but also to images, text files, spreadsheets, ZIP archives, HTML, and many other destination formats, making it easy to automate file processing within your applications.

Select from 300+ converters and tools!

File Converter Suite

High-performance and unbeatable accuracy document converter suite with support for over 300+ conversion.

Document Builder using Ruby

Generate dynamic DOCX and PDF documents like invoices, contracts, reports, on the fly.

Document Management tools

Protect, redact, compare, watermark, flatten, compress and modify your documents using ConvertAPI Ruby SDK.

Security and Decryption

Protect and unprotect PDFs, MS Office Powerpoint and MS Office Word documents.

AI Data Extractor

Built to scale with your business, whether you're handling a few conversions or thousands.

Archiving & Optimization

Reduce file sizes without losing quality. Archive converters are designed to handle over 100 different file formats.

Configure it online - we will generate the Ruby code for you!

Configure your file conversion directly online using our intuitive interface. Select the desired parameters and see the results in real-time. Once you're satisfied, we’ll automatically generate the Ruby code for you, making integration into your project effortless. No need to start from scratch - just copy the code and implement it seamlessly into your Ruby application!

Get started now

File conversion example using Ruby

The ConvertAPI Ruby library makes adding powerful document transformation capabilities to your Ruby projects both simple and efficient. Designed with ease-of-use in mind, the library’s intuitive API ensures you spend less time on repetitive tasks and more time delivering value in your Ruby applications.

With support for a vast selection of file formats, you can handle everything from PDF conversions to Office file manipulations with just a few lines of code. Combine and split documents, adjust quality and resolution, or securely redact sensitive information, this versatile toolkit gives you the flexibility to shape your workflows exactly as needed.

Install the ConvertAPI library into your Ruby project

To get started, install the ConvertAPI Ruby Gem:

# Add this line to your application's Gemfile:
gem 'convert_api'

Protect PDF using Ruby example

The ConvertAPI Ruby PDF Protect tool enables you to apply robust security measures to your PDF files directly from your Ruby applications. By adding passwords, setting permissions, or restricting printing and copying, you maintain strict control over document access.

The tool’s flexible options make it simple to configure the right level of protection, ensuring sensitive information remains safe, compliant, and tamper-resistant, without adding unnecessary complexity to your code.

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-library-js

// Code snippet is using the ConvertAPI Node.js Client: https://github.com/ConvertAPI/convertapi-nodejs

// Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php

// Code snippet is using the ConvertAPI Java Client: https://github.com/ConvertAPI/convertapi-java

// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet

# Code snippet is using the ConvertAPI Ruby Client: https://github.com/ConvertAPI/convertapi-ruby

# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python

// Code snippet is using the ConvertAPI Go Client: https://github.com/ConvertAPI/convertapi-go

REM Code snippet is using the command line utility program: https://github.com/ConvertAPI/convertapi-cli

<!-- For conversions with the multiple file result please refer to this example: https://repl.it/@ConvertAPI/HTML-Form-with-multiple-file-result -->

Convert a Stream

This example demonstrates converting text content directly from memory into a PDF, eliminating the need for intermediate file storage. It is ideal for applications that generate content dynamically and require immediate conversion without disk I/O. It's useful for applications that handle file data dynamically, such as web services or cloud-based systems, where writing to disk is undesirable.

Key Features:

  • Reads input data from a stream.
  • Processes the conversion entirely in memory.
  • Outputs the result to another stream.
ConvertApi.configure do |config|
  config.api_credentials = ENV['CONVERT_API_TOKEN'] # your api token
end

# Example of converting text to PDF
# https://www.convertapi.com/txt-to-pdf

content = 'Test file body'

io = StringIO.new
io.write(content)
io.rewind

# Use upload IO wrapper to upload data to the API
upload_io = ConvertApi::UploadIO.new(io, 'test.txt')

saved_files = ConvertApi
  .convert('pdf', {File: upload_io})
  .save_files(Dir.tmpdir)

puts "The PDF saved to: #{saved_files}"

Convert URL to PDF

Illustrates how to convert a live web page into a PDF by providing its URL, facilitating the capture of web content in a portable format. It's useful for archiving web pages or generating PDF versions of online content for offline access or record-keeping.

Key Features:

  • Accepts a web page URL as input.
  • Converts the web page to a PDF document.
  • Stores the PDF in a specified directory.
ConvertApi.configure do |config|
  config.api_credentials = ENV['CONVERT_API_TOKEN'] # your api token
end

# Example of converting Web Page URL to PDF file
# https://www.convertapi.com/web-to-pdf

result = ConvertApi.convert(
  'pdf',
  {
    Url: 'https://en.wikipedia.org/wiki/Data_conversion',
    FileName: 'web-example'
  },
  from_format: 'web',
  conversion_timeout: 180,
)

saved_files = result.save_files(Dir.tmpdir)

puts "The web page PDF saved to #{saved_files}"

Conversion Chaining

The following example demonstrates a multi-step conversion process, such as converting a DOCX file to PDF and then compressing the PDF, showcasing how to chain multiple conversions seamlessly. It is meant for complex workflows requiring multiple file transformations in a specific sequence.

Key Features:

  • Performs sequential conversions using intermediate results.
  • Manages multiple steps within a single process.
  • Outputs the final converted file after all transformations.
ConvertApi.configure do |config|
  config.api_credentials = ENV['CONVERT_API_TOKEN'] # your api token
end

# Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
# https://www.convertapi.com/doc/chaining

puts 'Converting PDF to JPG and compressing result files with ZIP'

jpg_result = ConvertApi.convert('jpg', {File: 'files/test.pdf'})

puts "Conversions done. Cost: #{jpg_result.conversion_cost}. Total files created: #{jpg_result.files.count}"

zip_result = ConvertApi.convert('zip', {Files: jpg_result.files})

puts "Conversions done. Cost: #{zip_result.conversion_cost}. Total files created: #{zip_result.files.count}"

saved_files = zip_result.save_files(Dir.tmpdir)

puts "File saved to #{saved_files}"

Get User Information

The final example illustrates how to retrieve account information, such as usage statistics and remaining conversion credits, using the ConvertAPI Ruby library. It is important for monitoring account usage and managing conversion quotas programmatically.

ConvertApi.configure do |config|
  config.api_credentials = ENV['CONVERT_API_TOKEN'] # your api token
end

# Retrieve user information
# https://www.convertapi.com/doc/user

puts ConvertApi.user

Using our Ruby SDK, you’ll gain access to an extensive collection of more than 300+ conversion and document management features, all conveniently housed within a single, integrated platform.

Using our Ruby library, you can supply documents using URLs, file streams, or local file paths, making it easy to integrate with your existing setup. To further streamline your operations, consider utilizing conversion workflows to apply multiple tasks to the same document sequentially.

For in-depth examples and expert tips, be sure to explore our GitHub repository.

Take a look at Ruby code samples

View on GitHub

Automate Your Document Management using Ruby

Take control of your documents with our Ruby document management SDK. From basic conversions to full workflow automation, we provide the expertise and tools you need to manage your documents efficiently.

Enterprise-Grade Security

We ensure that all document processing is handled securely in the cloud, adhering to industry-leading standards like ISO 27001, GDPR, and HIPAA. To enhance security even further, we can ensure that no files or data are stored on our servers and never leave your country.

Learn more about security

Businesses trust us

Highest rated File Conversion API on major B2B software listing platforms: Capterra, G2, and Trustpilot.

"ConvertAPI has been a game-changer for our document automation workflows. Their conversion accuracy and API reliability are unmatched in the industry for over 7 years."

"ConvertAPI is a reliable, cost-effective solution with a proven track record of stability. It has grown significantly in maturity, adopting enterprise-grade practices over the years."

"We've integrated ConvertAPI across our entire document processing platform. The performance is exceptional and the support team is always responsive. Highly recommended!"

Frequently Asked Questions

What is the ConvertAPI Ruby library used for?

The ConvertAPI Ruby library lets you integrate robust document conversion, manipulation, and management features directly into your Ruby applications. With support for hundreds of formats, including PDFs, Office files, and images - it makes it easy to handle a wide range of document-related tasks.

Which file formats are supported?

The library supports over 300+ file formats, allowing you to convert PDFs, Word documents, Excel spreadsheets, PowerPoint presentations, images, and more. This versatility makes it a one-stop solution for nearly any document transformation need.

Can I customize conversion settings?

Yes. You can fine-tune parameters such as resolution, image quality, page ranges, metadata options, and more. This gives you precise control over the output, ensuring it meets your specific requirements.

Does it handle large files or workflow operations?

Absolutely. The library is optimized to manage large documents and can employ workflows to process multiple conversions concurrently. This approach helps maintain performance and efficiency, even at scale.

How do I ensure data security?

ConvertAPI adheres to strong security standards. You can process files in memory or choose short-term, non-persistent storage. For more details on privacy and data handling, refer to our security and compliance.

Where can I find more examples and support?

Visit our GitHub repository for code samples, advanced usage scenarios, and best practices. If you have questions or need assistance, our support team is ready to help ensure you get the most out of ConvertAPI.

Try our Ruby library for free!