Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active June 17, 2022 14:26
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/1d5f0841f2c98783e1987b5160d8dfdf to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/1d5f0841f2c98783e1987b5160d8dfdf to your computer and use it in GitHub Desktop.
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