Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Combine PDF Files
# How to Combine Multiple PDF Files using REST API using Ruby
# 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 = 'merge/four-pages.pdf'
@item2 = GroupDocsMergerCloud::JoinItem.new
@item2.file_info = GroupDocsMergerCloud::FileInfo.new
@item2.file_info.file_path = 'merge/one-page.pdf'
@options = GroupDocsMergerCloud::JoinOptions.new
@options.join_items = [@item1, @item2]
@options.output_path = "merge/combine-files.pdf"
@result = @mergerApi.join(GroupDocsMergerCloud::JoinRequest.new(@options))
puts("Successfully merged PDF files using REST API in Ruby.")
# How to Merge Specific Pages of Multiple PDF Files using Ruby
# 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 = 'merge/ten-pages.pdf'
@item1.pages = [1, 5, 7]
@item2 = GroupDocsMergerCloud::JoinItem.new
@item2.file_info = GroupDocsMergerCloud::FileInfo.new
@item2.file_info.file_path = 'merge/four
-pages.pdf'
@item2.start_page_number = 1
@item2.end_page_number = 4
@item2.range_mode = "OddPages"
@options = GroupDocsMergerCloud::JoinOptions.new
@options.join_items = [@item1, @item2]
@options.output_path = "merge/join-pages.pdf"
@result = @mergerApi.join(GroupDocsMergerCloud::JoinRequest.new(@options))
puts("Merged multiple PDF files using Rest API.")

Learn how to merge PDF files in Ruby using Cloud REST API:

The following topics shall be covered in this article:

  1. PDF Merger REST API and Ruby SDK
  2. Combine Multiple PDF Files using REST API using Ruby
  3. Merge Specific Pages of Multiple PDF Files using Ruby
  4. Online PDF Merger for Free
# Load the PDF file merger gem
require 'groupdocs_merger_cloud'
# get client id and client secret
@client_id = "xxxxxxxxx-xxxxx-xxxx-xxxxxxxxxx"
@client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment