Merge PDF files in C++
Contents
[
Hide
]
Combine related PDF files into one document by appending their page collections.
Merge two PDF documents
- Open both input files as Document objects.
- Append the pages of the second document to the first with PageCollection::Add().
- Save the result with Document::Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <system/io/path.h>
using namespace System;
using namespace Aspose::Pdf;
void MergeDocuments(String inputDir, String outputFile) {
auto inputFile1 = System::IO::Path::Combine(inputDir, u"sample1.pdf");
auto inputFile2 = System::IO::Path::Combine(inputDir, u"sample2.pdf");
auto document1 = MakeObject<Document>(inputFile1);
auto document2 = MakeObject<Document>(inputFile2);
document1->get_Pages()->Add(document2->get_Pages());
document1->Save(outputFile);
}