PNG JPG BMP TIFF PDF
Aspose.PDF  for .NET

在 .NET SDK 中合并 PDF

在 C# Cloud API 中将两个 PDF 文件合并为一个,无需使用任何软件,如 Adobe PDF。

Get Started

如何使用 C# Cloud API 合并多个 PDF 文件

为了合并两个 PDF 文件,我们将使用 Aspose.PDF Cloud .NET SDK 此云 SDK 允许您轻松构建基于云的 PDF 创建、编辑和转换应用程序,适用于 C#、ASP.NET 或其他 .NET 语言的各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您还可以在包管理器控制台中使用以下命令。

命令


PM> Install-Package Aspose.Pdf-Cloud 

通过 Cloud .NET SDK 合并 PDF 的步骤

使用 Aspose.PDF Cloud .NET SDK API 的基本合并 PDF 程序仅需几行代码即可完成。

  1. 使用您的应用程序秘密和密钥创建一个新的配置对象
  2. 创建一个对象以连接到 Cloud API
  3. 上传您的文档文件
  4. 执行合并
  5. 下载结果
 

使用 C# 合并两个 PDF 文件


    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace Merges
    {
        public class MergeDocuments
        {
            public static async Task Merge(MergesHelper helper, List<string> files, string outputName, string remoteFolder)
            {
                Aspose.Pdf.Cloud.Sdk.Model.MergeDocuments documetItems = new(new List<string>());
    
                foreach (var file in files)
                {
                    await helper.UploadFile(Path.GetFileName(file));
                    documetItems.List.Add(Path.Combine( remoteFolder, file));
                }
    
                DocumentResponse response = await helper.pdfApi.PutMergeDocumentsAsync(outputName, documetItems, folder: remoteFolder);

                if (response == null)
                    Console.WriteLine("MergeDocuments(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("MergeDocuments(): Failed to documents.");
                else
                {
                    Console.WriteLine("MergeDocuments(): documents successfully merged to '{0}' file.", outputName);
                    await helper.DownloadFile(outputName);
                }
            }
        }
    }