PDF (Portable Document Format) is widely used for sharing documents while preserving their formatting and layout. In certain scenarios, you may need to combine multiple PDF files into a single document to streamline information or improve accessibility. GroupDocs.Merger Cloud SDK for .Net provides a powerful and intuitive way to merge PDF files programmatically, saving you time and effort. In this article, we will explore how to merge and combine PDF files in C# using REST API.
The following topics shall be covered in this article:
- C# REST API to Merge PDF Files and C# SDK Installation
- Merge Multiple PDF Files into One in C# using REST API
- Merge Specific Pages of PDF Files in C# using REST API
C# REST API to Merge PDF Files and C# SDK Installation
GroupDocs.Merger Cloud SDK for .NET is a powerful and reliable solution that allows developers to incorporate PDF merging capabilities into their C# applications. It offers a comprehensive set of features and functions to merge and combine PDF files seamlessly. By using the SDK, you can merge multiple supported document formats into a single document, preserving their original formatting, layout, and content. The SDK can be integrated into a C# based application to simplify your development process.
You can install GroupDocs.Merger Cloud SDK for .NET to your project from the NuGet Package manager or using the following command in the .NET CLI:
dotnet add package GroupDocs.Merger-Cloud --version 23.4.0
Next, collect the Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Add Client ID and Client Secret in the code as demonstrated below:
Merge Multiple PDF Files into One in C# using REST API
Now that we have our development environment set up and the SDK installed, let’s proceed with merging PDF files. Follow these steps:
Upload the Files
Firstly, upload the PDF document to the cloud storage using any of the following methods:
- Using the dashboard
- Upload all files one by one using Upload File API from the browser
- Upload programmatically using the code example given below:
As a result, the uploaded PDF file will be available in the files section of your dashboard on the cloud.
Merge PDF Documents in C#
Here are the steps and an example code snippet that demonstrates how to merge multiple PDF documents into a single file programmatically in C#.
- Firstly, create an instance of the DocumentApi class.
- Secondly, create an instance of the JoinItem class.
- Thirdly, set the input file path for the first JoinItem in the FileInfo.
- Then, create a new instance of the JoinItem for the second input file.
- Now, provide the input file path for the second JoinItem in the FileInfo.
- You can add more JoinItems to merge more PDF files.
- Next, create an instance of the JoinOptions class.
- Add a comma-separated list of created join items.
- Also, set the output file path on the cloud.
- Now, create an instance of the JoinRequest and pass the JoinOptions parameter.
- Lastly, get results by calling the join() method of the DocumentApi and passing the JoinRequest parameter.
The following code snippet shows how to merge multiple PDF files into one in C# using REST API:
With just a few lines of code, you can now easily merge PDF files using GroupDocs.Merger Cloud SDK for .Net.
Download the File
The above code example will save the merged PDF file on the cloud. You can download it using the following code snippet:
Merge Specific Pages of PDF Files in C# using REST API
The GroupDocs.Merger Cloud SDK offers various advanced options to customize the PDF merging process according to your requirements. You can easily combine specific pages from multiple PDF files into one file programmatically by following the steps below:
- Firstly, create an instance of the DocumentApi class.
- Secondly, create an instance of the JoinItem class.
- Thirdly, set the input file path for the first JoinItem in the FileInfo.
- Next, provide the comma-separated list of pages to join.
- Then, create a new instance of the JoinItem for the second input file.
- Now, provide the input file path for the second JoinItem in the FileInfo.
- Set the StartPageNumber, EndPageNumber, and RangeMode values.
- You can add more JoinItems to merge more PDF files.
- Next, create an instance of the JoinOptions class.
- Add a comma-separated list of created join items.
- Also, set the output file path on the cloud.
- Now, create an instance of the JoinRequest and pass the JoinOptions parameter.
- Finally, get results by calling the join() method of the DocumentApi and passing the JoinRequest parameter.
The following code snippet shows how to merge specific pages from two PDF files in C# .NET using REST API:
Free Online PDF Merger
How to merge PDF files into one online for free? Please try the following online PDF Merger application to combine multiple PDF files into a single file from any device.
Summing up
In conclusion, the GroupDocs.Merger Cloud SDK for .Net provides a reliable and efficient solution for merging PDF files in C# applications. This blog post has taught us:
- how to combine multiple PDF files into one in C# .NET on the cloud;
- programmatically upload and download the PDF file from the cloud;
- how to combine specific pages of multiple PDF files into a single file in C#;
- and free online PDF files merger tool.
Additionally, 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. Complete source code of GroupDocs.Merger Cloud SDK for .Net is freely available on GitHub.
Finally, we keep writing new blog articles on different file formats and parsing them using REST API. So, please get in touch for the latest updates.
Ask a question
In case you would have any queries about the PDF Merger API, please feel free to contact us via our forum.
FAQs
Is it possible to merge specific pages from different PDF files using C#?
Yes, using the GroupDocs.Merger Cloud SDK for .NET, you can specify page ranges to merge specific pages from different PDF files. This gives you the flexibility to extract and combine relevant information as needed.
How can I install an online PDF merger library?
You can obtain the GroupDocs.Merger Cloud SDK for .Net from the official GroupDocs website. Follow the installation instructions provided to set up the SDK in your C# application.
How to merge multiple PDF files online for free?
Please visit the online PDF Merger tool to merge and combine two or more PDF files for free, in seconds.
See Also
If you want to learn more about related topics, we recommend reading the articles listed below: