PDF 檔案合併 Python

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

如何使用 Python for .NET 庫合併 PDF 檔

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

Python Package Manager Console

pip install aspose-pdf

通過Python合併 PDF 檔


您需要使用 [Aspose.PDF for .NET](https://releases.aspose.com/pdf/net) 來嘗試環境中的代碼。

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

Python - 用於合併 PDF 檔的範例代碼。

    import aspose.pdf as ap

    input_pdf_1 = DIR_INPUT_DOCUMENTS + "concat1.pdf"
    input_pdf_2 = DIR_INPUT_DOCUMENTS + "concat2.pdf"
    output_pdf = DIR_OUTPUT_DOCUMENTS + "merge_pdf_files.pdf"

    # Open first document
    document1 = ap.Document(input_pdf_1)
    # Open second document
    document2 = ap.Document(input_pdf_2)

    # Add pages of second document to the first
    document1.pages.add(document2.pages)

    # Save concatenated output file
    document1.save(output_pdf)