PNG
JPG
BMP
TIFF
PDF
使用 C# Cloud API 合并多个 PDF 文件
为了合并两个 PDF 文件,我们需要使用 Aspose.PDF Cloud .NET SDK 此 Cloud SDK 使您可以使用 C#、ASP.NET 或其他 .NET 语言轻松构建基于云的 PDF 创建、编辑和转换应用程序,以适应各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 然后进行安装。您也可以从包管理器控制台执行以下命令。
命令
PM> Install-Package Aspose.Pdf-Cloud
通过云 .NET SDK 合并 PDF 的步骤
使用 Aspose.PDF Cloud .NET SDK API 只有几行代码即可将 PDF 文件进行基本的编程合并。
- 使用您的应用程序密钥和密码创建一个新的配置对象
- 创建一个对象以连接到 Cloud API
- 上传您的文档文件
- 执行合并
- 下载結果
使用 C# 合并两个 PDF 文件
internal static void MergePdf()
{
const string localImageFileName = @"C:\Samples\sample.pdf";
const string storageFileName1 = "sample1.pdf";
const string storageFileName2 = "sample2.pdf";
const string resultFileName = "merged-doc.pdf";
// Get your AppSid and AppSecret https://dashboard.aspose.cloud (free registration required).
var pdfApi = new PdfApi(AppSecret, AppSid);
using var file = File.OpenRead(localImageFileName);
pdfApi.UploadFile(storageFileName1, file);
pdfApi.CopyFile(storageFileName1, storageFileName2);
var documentsToBeMerged = new List<string>()
{
storageFileName1, storageFileName2
};
var documents = new Aspose.Pdf.Cloud.Sdk.Model.MergeDocuments(documentsToBeMerged);
pdfApi.PutMergeDocuments(resultFileName, documents);
var response = pdfApi.DownloadFile(resultFileName);
response.CopyTo(File.OpenWrite(resultFileName));
Console.WriteLine();
}