How to Convert a PDF File to PDF/A in Ruby

2 min readMay 10, 2021

If you run into compatibility issues when attempting to share a PDF file, it may be helpful to convert the document into the universally standardized PDF/A format. In this brief tutorial, we will demonstrate how you can transform your PDF into a PDF/A using an API in Ruby. All you will need to complete the process are the target PDF file and your API key; there is an additional option that allows you to specify your level of conformance to PDF/A-1b or PDF/A-2b, depending on your needs. The default conformance level is PDF/A-1b.

To begin the process, we will add the Ruby client to our Gemfile:

gem 'cloudmersive-convert-api-client', '~> 2.1.6'

Next, we can input the parameters specified above in the code provided below:

# load the gem
require 'cloudmersive-convert-api-client'
# setup authorization
CloudmersiveConvertApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
api_instance = CloudmersiveConvertApiClient::EditPdfApi.newinput_file ='/path/to/inputfile') # File | Input file to perform the operation on.opts = {
conformance_level: 'conformance_level_example' # String | Optional: Select the conformance level for PDF/A - specify '1b' for PDF/A-1b or specify '2b' for PDF/A-2b; default is PDF/A-1b
#Convert a PDF file to PDF/A
result = api_instance.edit_pdf_convert_to_pdf_a(input_file, opts)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling EditPdfApi->edit_pdf_convert_to_pdf_a: #{e}"

And that’s it! If you need to obtain an API key, you can register for a free account on the Cloudmersive website; this will also provide access to 800 monthly calls across our API library.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.