How to convert HTML to a Word DOCX Document in Ruby
1 min readAug 9, 2019
Today’s topic: converting HTML to DOCX made easy. Here’s how:
- Add our Convert API Client to your Gemfile with this snippet here.
gem 'cloudmersive-convert-api-client', '~> 1.3.3'
2. Call convert_web_html_to_docx as seen 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'
endapi_instance = CloudmersiveConvertApiClient::ConvertWebApi.newinput_request = CloudmersiveConvertApiClient::HtmlToOfficeRequest.new # HtmlToOfficeRequest |begin
#HTML to DOCX
result = api_instance.convert_web_html_to_docx(input_request)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ConvertWebApi->convert_web_html_to_docx: #{e}"
end
And that’s all she wrote! Images may be included if they have qualified URLs. Rich text formatting also carries over.