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 PagesMove
        {
            public static async Task Move(string documentName, string outputName, int pageNumber, int newPageNumber, 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]);
                }

                // Move page from the PDF to new positionon in cloud storage.
                AsposeResponse response = await pdfApi.PostMovePageAsync(documentName, pageNumber, newPageNumber, folder: remoteFolder);

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