Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/a26541c1465e9dcab2cfbae19fb1ba1d to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/a26541c1465e9dcab2cfbae19fb1ba1d to your computer and use it in GitHub Desktop.
Ruby File Conversion APIs for PDF to Editable Word Document
# For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-ruby-samples
# API initialization: Create an instance of the conversion APIs
@fileApi = GroupDocsConversionCloud::ConvertApi.from_keys(@client_id, @client_secret)
# Prepare convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "conversion/four-pages.pdf"
@settings.format = "docx"
loadOptions = GroupDocsConversionCloud::PdfLoadOptions.new
loadOptions.password = ""
loadOptions.hide_pdf_annotations = true
loadOptions.remove_embedded_files = false
loadOptions.flatten_all_fields = true
@settings.load_options = loadOptions
@settings.convert_options = GroupDocsConversionCloud::DocxConvertOptions.new
@settings.output_path = "conversion"
# Convert
result = @fileApi.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("File converted successfully completed.")
# API initialization: Create an instance of the conversion APIs
@fileApi = GroupDocsConversionCloud::ConvertApi.from_keys(@client_id, @client_secret)
@settings = GroupDocsConversionCloud::ConvertSettings.new()
@settings.storage_name = @groupdocs_storage;
@settings.file_path = "conversion/four-pages.pdf"
@settings.format = "docx"
@loadOptions = GroupDocsConversionCloud::PdfLoadOptions.new()
@loadOptions.password = "password"
@loadOptions.hide_pdf_annotations = true
@loadOptions.remove_embedded_files = false
@loadOptions.flatten_all_fields = true
@settings.load_options = @loadOptions
@convertOptions = GroupDocsConversionCloud::DocxConvertOptions.new()
@convertOptions.from_page = 1
@convertOptions.pages_count = 1
@settings.convert_options = @convertOptions
@settings.output_path = "conversion"
@request = GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings)
@response = @fileApi.convert_document(@request)
puts("Document converted successfully: " + (@response).to_s)
# API initialization: Create an instance of the conversion APIs
@fileApi = GroupDocsConversionCloud::FileApi.from_keys(@client_id, @client_secret)
# Download File Request
@request = GroupDocsConversionCloud::DownloadFileRequest.new("conversion/four-pages.docx", @groupdocs_storage)
@response = @fileApi.download_file(@request)
puts("File download successfully completed." + (@response).to_s )

Learn how to convert PDF to Editable Word Document in Ruby using REST API:

The following topics shall be covered in this article:

PDF Conversion REST API and Ruby SDK Convert PDF to Editable Word Documents using REST API in Ruby PDF to Word Conversion with Advance Options

# API initialization: Create an instance of the conversion APIs
@fileApi = GroupDocsConversionCloud::FileApi.from_keys(@client_id, @client_secret)
# Upload file to cloud storage
@pdffile = "#{Rails.root}/public/groupdocs-files/four-pages.pdf"
@fileStream = File.new(@pdffile, "r")
@request = GroupDocsConversionCloud::UploadFileRequest.new('conversion/four-pages.pdf', @fileStream, @groupdocs_storage)
@response = @fileApi.upload_file(@request)
@fileStream.close()
puts("File Uploading completed." + (@response).to_s )
# Get your client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
# Load the gem in your ruby application for http://api.groupdocs.cloud
require 'groupdocs_conversion_cloud'
@client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Add your storage name here
@groupdocs_storage = "MyStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment