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/cf4ff37d44f27d2ea14f3aab34bb5b7d to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/cf4ff37d44f27d2ea14f3aab34bb5b7d to your computer and use it in GitHub Desktop.
Merge Multiple File Types using REST API
# Create an instance of the File API
@fileApi = GroupDocsConversionCloud::FileApi.from_keys(@client_id, @client_secret)
# Download combined document request
@request = GroupDocsConversionCloud::DownloadFileRequest.new("combine-multiple-files/combined.pdf", @mystorage)
@response = @fileApi.download_file(@request)
puts("PDF file downloaded successfully." + (@response).to_s )
# How to Merge Specific Pages of Multiple File Types in Ruby?
# Create an instance of the Document API
@documentApi = GroupDocsMergerCloud::DocumentApi.from_keys(@client_id, @client_secret)
@item1 = GroupDocsMergerCloud::JoinItem.new
@item1.file_info = GroupDocsMergerCloud::FileInfo.new
@item1.file_info.file_path = 'combine-multiple-files/ten-pages.pdf'
@item1.pages = [3, 6, 8]
@item2 = GroupDocsMergerCloud::JoinItem.new
@item2.file_info = GroupDocsMergerCloud::FileInfo.new
@item2.file_info.file_path = 'combine-multiple-files/four-pages.docx'
@item2.start_page_number = 1
@item2.end_page_number = 4
@options = GroupDocsMergerCloud::JoinOptions.new
@options.join_items = [@item1, @item2]
@options.output_path = "combine-multiple-files/combined.pdf"
@result = @documentApi.join(GroupDocsMergerCloud::JoinRequest.new(@options))
puts("Output file path: " + @result.path)
puts("Merged multiple types documents pages in Ruby.")
# How to Merge PDF and Excel into PDF?
# Create an instance of the Document API
@documentApi = GroupDocsMergerCloud::DocumentApi.from_keys(@client_id, @client_secret)
@item1 = GroupDocsMergerCloud::JoinItem.new
@item1.file_info = GroupDocsMergerCloud::FileInfo.new
@item1.file_info.file_path = 'combine-multiple-files/two-pages.pdf'
@item1.file_info.password = 'password'
@item2 = GroupDocsMergerCloud::JoinItem.new
@item2.file_info = GroupDocsMergerCloud::FileInfo.new
@item2.file_info.file_path = 'combine-multiple-files/four-pages.docx'
@options = GroupDocsMergerCloud::JoinOptions.new
@options.join_items = [@item1, @item2]
@options.output_path = "combine-multiple-files/combined.pdf"
@result = @documentApi.join(GroupDocsMergerCloud::JoinRequest.new(@options))
puts("Resultant file path: " + @result.path)
puts("Successfully combined multiple document types in Ruby.")
# How to Merge PDF and Excel into PDF?
# Create an instance of the Document API
@mergerApi = GroupDocsMergerCloud::DocumentApi.from_keys(@client_id, @client_secret)
@item1 = GroupDocsMergerCloud::JoinItem.new
@item1.file_info = GroupDocsMergerCloud::FileInfo.new
@item1.file_info.file_path = 'combine-multiple-files/two-pages.pdf'
@item1.file_info.password = 'password'
@item2 = GroupDocsMergerCloud::JoinItem.new
@item2.file_info = GroupDocsMergerCloud::FileInfo.new
@item2.file_info.file_path = 'combine-multiple-files/four-pages.xlsx'
@options = GroupDocsMergerCloud::JoinOptions.new
@options.join_items = [@item1, @item2]
@options.output_path = "combine-multiple-files/combined.pdf"
@result = @documentApi.join(GroupDocsMergerCloud::JoinRequest.new(@options))
puts("Resultant file path: " + @result.path)
puts("Successfully combined PDF and Excel into PDF using Ruby.")
# How to Merge PDF and PowerPoint into PDF?
# Create an instance of the Document API
@documentApi = GroupDocsMergerCloud::DocumentApi.from_keys(@client_id, @client_secret)
@item1 = GroupDocsMergerCloud::JoinItem.new
@item1.file_info = GroupDocsMergerCloud::FileInfo.new
@item1.file_info.file_path = 'combine-multiple-files/two-pages.pdf'
@item1.file_info.password = 'password'
@item2 = GroupDocsMergerCloud::JoinItem.new
@item2.file_info = GroupDocsMergerCloud::FileInfo.new
@item2.file_info.file_path = 'combine-multiple-files/five-pages.pptx'
@options = GroupDocsMergerCloud::JoinOptions.new
@options.join_items = [@item1, @item2]
@options.output_path = "combine-multiple-files/combined.pdf"
@result = @documentApi.join(GroupDocsMergerCloud::JoinRequest.new(@options))
puts("Resultant file path: " + @result.path)
puts("Successfully combined PDF and PowerPoint into PDF using Ruby.")

Learn how to merge multiple file types in Ruby using Cloud REST API:

The following topics shall be covered in this article:

  1. Files Merger REST API and Ruby SDK
  2. Merge Multiple File Types into One Document using Ruby
  3. How to Merge PDF and Excel into PDF
  4. How to Merge PDF and PowerPoint into PDF
  5. Combine Specific Pages of Multiple File Types in Ruby
  6. Online Multiple File Types Merger
# Create an instance of the File API
@fileApi = GroupDocsConversionCloud::FileApi.from_keys(@client_id, @client_secret)
# Upload documents one by one to cloud storage from local system
@document = "#{Rails.root}/public/groupdocs-files/two-pages.pdf"
@fileStream = File.new(@document, "r")
@request = GroupDocsConversionCloud::UploadFileRequest.new('combine-multiple-files/two-pages.pdf', @fileStream, @mystorage)
@response = @fileApi.upload_file(@request)
puts("Document successfully uploaded to the cloud." + (@response).to_s )
# Load the multiple file types merger gem
require 'groupdocs_merger_cloud'
@client_id = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx"
@client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Define your storage name
@mystorage = "MYStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment