Combining multiple PDF files into a single document can simplify tasks such as report generation, legal documentation, and project management. This process not only reduces clutter but also enhances accessibility and sharing capabilities. By merging PDFs, you can ensure that all relevant information is consolidated, making it easier to review and distribute.
API to Combine PDF Files
Combining PDF files programmatically is made simple and efficient with the GroupDocs.Merger Cloud SDK for .NET. This powerful SDK allows developers to merge multiple PDF documents seamlessly within their .NET applications. Now, in order to install the SDK, please search GroupDocs.Merger-Cloud in NuGet package manager and click the Install button. Another option is to execute the following command in package manager console.
NuGet\Install-Package GroupDocs.Merger-Cloud -Version 23.10.0
Then, we need to obtain the personalized API credentials(i.e. Client ID and Client Secret). Please follow the instructions specified in this short tutorial explaining the details on how to get the API credentials.
Combine PDF Files in C#
In this section, we are going to leverage the robust features of GroupDocs.Merger, so we can easily automate the process of combining PDFs in C# .NET.
- Create an instance of
Configuration
class where we pass client credentials as arguments.
var configurations = new Configuration(clientId, clientSecret1);
- Initialize the
DocumentApi
where we pass Configuration object as an input argument.
var newApiInstance = new DocumentApi(configurationSettings);
- Create an object where we define the name of input PDF and count of pages to be merged.
var item1 = new JoinItem
- Create JoinRequest where as pass
JoinOptions
object as an argument.
var requestOutput = new JoinRequest(options);
- Call the API to combine PDF document and store the resultant PDF to cloud storage.
var response = newApiInstance.Join(requestOutput);
The sample PDF files used in the above example can be downloaded from ten-pages.pdf and Binder1.pdf.
Concatenate PDF Documents with cURL Commands
Merging PDF files using GroupDocs.Merger Cloud and cURL commands offers a streamlined and efficient solution for combining documents. This approach is particularly beneficial for automating document management tasks, as it allows for the quick and easy consolidation of multiple PDF files into a single document.
In this approach, first we need to generate the JWT access token based on client credentials (as shown in command below).
curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=b7efc309-156b-4496-9501-68197f85c25a&client_secret=985132b15703be48a4bdf897e6c05777" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Once the JWT token is generated, please execute the following command to merge 2nd and 3rd page of first file with page number 2 to 5 of second PDF document. The resultant file is then stored in cloud storage.
curl -v "https://api.groupdocs.cloud/v1.0/merger/join" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"JoinItems\": [ { \"FileInfo\": { \"FilePath\": \"{sourceFile1}\", \"StorageName\": \"internal\", }, \"Pages\": [2,3], },{ \"FileInfo\": { \"FilePath\": \"{sourceFile2}\", \"StorageName\": \"internal\", }, \"StartPageNumber\": 2, \"EndPageNumber\": 5 } ], \"OutputPath\": \"{resultantFile}\"}"
Please replace sourceFile1
with the name of first input PDF file and sourceFile2
with the name of second PDF document. Then, replace resultantFile
with the name of resultant PDF document and accessToken
with personalized JWT access token.
Tyr our Free PDF Merger
You may consider evaluating our lightweight and supper-efficient PDF Merger App. This App is built on top of GroupDocs.Merger Cloud APIs and enables you to witness the amazing capabilities of the API offering PDF concatenate features.
Useful Links
Conclusion
In conclusion, combining PDF files using GroupDocs.Merger Cloud SDK for .NET or leveraging the cURL commands provides a highly efficient and reliable solution for managing documents. Both approaches offer unique advantages, i.e. the SDK provides a more integrated experience for .NET developers and cURL commands offer simplicity and flexibility for quick, command-line operations. Therefore, we encourage you to explore and utilize GroupDocs.Merger Cloud for PDF merging needs and take advantages of the robust features of Cloud SDK to enhance your document management processes.
Related Articles
We highly recommend visiting the following links to learn more about: