Combine and Merge Multiple File Types into One Document using Ruby

Merge Multiple File Types into One Document using Ruby

The merging of different documents of the same or different types allows gathering the scattered data or information into one single file. We can easily merge multiple documents of different file types into one file on the cloud. In this article, we will learn how to merge multiple file types into one document using Ruby REST API.

The following topics shall be covered in this article:

Files Merger REST API and Ruby SDK

For merging multiple files, we will be using the Ruby SDK of GroupDocs.Merger Cloud API. It enables us to combine, split, remove and rearrange a single page or a collection of pages from supported document formats of Word, Excel, PowerPoint, Visio drawings, PDF, and HTML. Please install it using the following command in the console:

gem install groupdocs_conversion_cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Merge Multiple File Types into One Document using Ruby

We can combine documents of multiple files types programmatically on the cloud by following the steps given below. You can upload the documents to the cloud and as a result, uploaded files will be available in the files section of your dashboard on the cloud. Now, we can merge the files of different types into a single file by following the steps given below:

  • Firstly, create an instance of the DocumentApi.
  • Next, provide the input file path for first JoinItem.
  • Then, provide the input file path for second JoinItem.
  • Optionally, repeat the above steps to add more files.
  • After that, define the JoinOptions and set the path of the output file.
  • Finally, call the join() method and save the merged document.

The following code sample shows how to merge different file types using a REST API in Ruby.

Finally, the above code sample will save the merged PDF file on the cloud. The output document shall contain all the pages of the PDF document and then all the pages of the Word document.

How to Merge PDF and Excel into PDF

We can merge PDF and Excel files into a PDF by following the steps mentioned earlier. However, we just need to provide PDF and Excel document paths as the first and second JoinItems. The following code sample shows how to merge a PDF document and Excel sheet into a PDF file using a REST API in Ruby.

How to Merge PDF and PowerPoint into PDF

We can also merge PDF documents and PowerPoint presentations into PDF by fusing REST API in Rubyollowing the steps mentioned earlier. However, we just need to provide PDF and PowerPoint document paths as the first and second JoinItems. The following code sample shows how to merge a PDF document and a PowerPoint presentation into a PDF file using a REST API in Ruby.

Combine Specific Pages of Different File Types in Ruby

We can merge selected pages from documents of different types into a single file by following the steps given below:

  • Firstly, create an instance of the DocumentApi.
  • Next, provide the input file path for first JoinItem.
  • Then, provide specific page numbers to merge.
  • Next, provide the input file path for second JoinItem.
  • Then, define the pages range to merge with start page number and end page number.
  • After that, define the JoinOptions and set the path of the output file.
  • Finally, call the join() method and save the merged document.

The following code sample shows how to merge specific pages of different file types using a REST API in Ruby.

Online Multiple File Types Merger

Please try the following free online merging tool, which is developed using the above API. https://products.groupdocs.app/merger/

Conclusion

In this article, we have learned:

  • how to merge documents of multiple file types in Ruby;
  • how to merge PDF and Excel into PDF;
  • how to merge PDF and PowerPoint into PDF;

Besides, you can learn more about GroupDocs.Merge Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

If you have any queries about our Multiple File Types Merger, please feel free to ask us on the Forum

See Also