PDF 檔案合併 C++

在瀏覽器中合併 PDF 文件,而無需 Adobe 雜技演員或自動化 - C++。

如何使用 C++ 庫合併 PDF 檔

为了合并 PDF 文件,我们将使用 Aspose.PDF for C++ API,这是一款适用于 cpp 平台的功能丰富、功能强大且易于使用的文档操作 API。我们的 C++ 库可以将文档从任何支持的下载格式转换为任何支持的保存格式。Aspose.PDF for C++ 库提供了相当通用的解决方案,可以帮助你解决转换文档的任务。Aspose.PDF 支持最多的常用文档格式,用于加载和保存。请您注意,当前部分仅描述了热门转化次数。当前页面提供有关将格式转换为格式的信息。但是,有许多组合可以转换文件。有关支持格式的完整列表,请参阅 [支持的文件格式] 部分 (https://docs.aspose.com/pdf/cpp/supported-file-formats/)。打开 NuGet 包管理器,搜索 aspose.pdf 并安装。您也可以使用软件包管理器控制台中的以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通過C++合併 PDF 檔


您需要為C++.PDF [Aspose https://releases.aspose.com/pdf/cpp) 才能在您的環境中嘗試代碼。

  1. 開啟第一個文件。
  2. 開啟第二個文件。
  3. 將第二個文件的頁面添加到第一個文件。
  4. 儲存串聯的輸出檔

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);