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. Cloud APIに接続するオブジェクトを作成します。
  3. PDFをクラウドストレージにアップロードします。
  4. クラウドストレージ内のPDFからページを削除します。
  5. 応答を確認し、結果をログに記録します。
  6. 更新されたファイルをローカルで使用するためにダウンロードします。
 

このサンプルコードはPDFドキュメントからページを削除する方法を示しています


    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace Pages
    {
        public class PagesDelete
        {
            public static async Task Delete(string documentName, string outputName, int pageNumber, 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]);
                }

                // Delete page from the PDF on cloud storage.
                AsposeResponse response = await pdfApi.DeletePageAsync(documentName, pageNumber, folder: remoteFolder);

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