In various scenarios, you may need to merge multiple PDF files into a single one. For example, merging the content from a similar type of documents such as resumes, receipts, and etc. Aspose.PDF lets you automate the PDF merging process from within your web, desktop, or mobile applications. In this article, you are going to learn how to merge multiple PDF files using the C++ variant of Aspose.PDF.
C++ PDF Merger API - Free Download
Aspose.PDF for C++ is a feature-rich PDF manipulation API that lets you create and process PDF files seamlessly. The API’s PDF merging feature allows you to combine two or more PDF files within a few lines of code. You can either download the API’s package or get it installed using NuGet.
Steps to Merge PDF Files
Before jumping to the code, let’s first have a look at what are the basic steps needed to merge PDF files.
- Load the source and target PDF files.
- Fetch the pages from the source PDF file.
- Add fetched pages to the target PDF file.
- Save the target PDF file.
Now, let’s transform these steps into C++ coding instructions using Aspose.PDF for C++.
Merge Two PDF Files using C++
The following are the steps along with the API references of the classes and methods used to merge PDF files.
- Create an object of Document class to load the first PDF file.
- Repeat the first step to load the second PDF file.
- Access the PageCollection of the second document using doc2->get_Pages() method.
- Add fetched pages to the first document using doc1->get_Pages()->Add(PageCollection).
- Save the first document using doc1->Save(String) method.
The following code sample shows how to merge two PDF files.
In this article, you have seen how to merge two or more PDF documents using C++. You can implement this feature in your C++ based applications in order to automate the PDF merging. Explore more about the C++ PDF API using the documentation.