HTML JPG PDF XML DOCX
  Product Family
PDF

.NET SDKを通じてPDFに新しいページを追加

.NETを使用してPDFドキュメントにページを追加するためのAPI。

Get Started

Cloud .NET SDKを使用してPDFドキュメントにページを追加する方法

Cloud .NET SDKを使用して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を使用してページを追加する手順

Aspose.PDF Cloudの開発者は、ほんの数行のコードでPDFドキュメントにページを読み込み、追加することができます。

  1. アプリケーションのシークレットとキーを使用して新しいConfigurationオブジェクトを作成します。
  2. クラウドAPIに接続するためのオブジェクトを作成します。
  3. PDFをクラウドストレージにアップロードします。
  4. クラウドストレージ内のPDFに新しいページを追加します。
  5. 応答を確認し、結果をログに記録します。
  6. 更新されたファイルをローカルで使用するためにダウンロードします。
 

このサンプルコードはPDFドキュメントにページを追加する方法を示しています


    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace Pages
    {
        public class PagesAdd
        {
            public static async Task Append(string documentName, string outputName, string localFolder, string remoteFolder)
            {
		// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
		pdfApi = new PdfApi(AppSecret, AppSid);

                using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
		{ // Upload the local PDF to cloud storage folder name.
                    FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
                    Console.WriteLine(uploadResponse.Uploaded[0]);
                }

                // Append new page to the PDF on cloud storage.
                DocumentPagesResponse response = await pdfApi.PutAddNewPageAsync(documentName, folder: remoteFolder);

                // Checks the response and logs the result.
                if (response == null)
                    Console.WriteLine("PagesAdd(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("PagesAdd(): Failed to append page to the document.");
                else
                { // Downloads the updated file for local use.
                    Console.WriteLine("PagesAdd(): page successfully appended to the document '{0}.", documentName);
                    Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
                    using var fileStream = File.Create(Path.Combine(localFolder, "append_pages_" + outputName));
                    stream.Position = 0;
                    await stream.CopyToAsync(fileStream);
                    Console.WriteLine("PagesAdd(): File '{0}' successfully downloaded.", "append_pages_" + outputName);
                }
            }
        }
    }