為了合併 PDF 文件,我們將使用 Aspose.PDF for C++ API,這是一個功能豐富、強大且易於使用的文件操作 API,適用於 cpp 平台。我們的 C++ 程式庫可以將任何受支援的下載格式的文件轉換為任何受支援的儲存格式。 Aspose.PDF for C++ 函式庫提供了相當通用的解決方案,可以幫助您完成文件轉換任務。 Aspose.PDF 支援最多的常用文件格式,包括載入和儲存。請注意,本節僅介紹常用的轉換。本頁提供有關格式轉換的資訊。但是,文件轉換的組合方式有很多種。有關支援格式的完整列表,請參閱 支援的文件格式 部分。開啟 NuGet 套件管理器,搜尋 Aspose.PDF 並安裝。您也可以從軟體包管理器控制台使用以下命令。
PM > Install-Package Aspose.PDF.Cpp
通過C++合併 PDF 檔
你需要 Aspose.PDF for C++ 才能在你的环境中试用代码。
- 開啟第一個文件。
- 開啟第二個文件。
- 將第二個文件的頁面添加到第一個文件。
- 儲存串聯的輸出檔
C++-合并 PDF 文件的示例代码
// String for path name
String _dataDir("C:\\Samples\\");
// String for input file name
String pdfDocumentFileName1("Concat1.pdf");
String pdfDocumentFileName2("Concat2.pdf");
String outputFileName("ConcatenatePdfFiles.pdf");
// Open document
auto pdfDocument1 = MakeObject<Document>(_dataDir + pdfDocumentFileName1);
auto pdfDocument2 = MakeObject<Document>(_dataDir + pdfDocumentFileName2);
// Add pages of second document to the first
pdfDocument1->get_Pages()->Add(pdfDocument2->get_Pages());
// Save concatenated output file
pdfDocument1->Save(_dataDir+outputFileName);