HTML JPG PDF XML DOCX
  Product Family
PDF

.NET SDKを使用してPDFのテキスト注釈を置換

Aspose.PDF Cloud .NET SDKを使用してPDF文書内の注釈を置換するためのAPI。

Get Started

Cloud .NET SDKを使用して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を使用して注釈を置換する手順

Aspose.PDF Cloudの開発者は、数行のコードでPDF文書内の注釈を簡単に読み込んで置換できます。

  1. 文書をクラウドにアップロードします。
  2. GetTextAnnotationAsync()を使用して注釈を取得します。
  3. 注釈の内容とアイコンを変更します。
  4. 変更をクラウドに保存します。
  5. 更新された文書をダウンロードします。
 

このサンプルコードは、C#を使用してPDF文書内でテキスト注釈を置換する方法を示しています


    using Aspose.Pdf.Cloud.Sdk.Model;
    using System.Runtime.Intrinsics.X86;

    namespace Annotations
    {
        public class ReplaceAnnotation
        {
            public static async Task<TextAnnotation> GetAnnotationAsync(AnnotationsHelper helper, string documentName, string annotationId, string remoteFolder)
            {
                // Get annotation by Id in the PDF document.
                TextAnnotation annotationResult = null;
                TextAnnotationResponse response = await helper.pdfApi.GetTextAnnotationAsync(documentName, annotationId, folder: remoteFolder);

                if (response == null)
                    Console.WriteLine("GetAnnotationAsync(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("GetAnnotationAsync(): Failed to request text annotation from the document.");
                else
                {
                    Console.WriteLine("GetAnnotationAsync(): annotation '{0}' with '{1}' contents successfully found in the document '{2}.", response.Annotation.Id, response.Annotation.Contents, documentName);
                    annotationResult = response.Annotation;
                }
                return annotationResult;
            }

            public static async Task ModifyAsync(AnnotationsHelper helper, string documentName, string outputName, string annotationId, string remoteFolder)
            {
                // Change annotation on the page in the PDF document.
                await helper.UploadFile(documentName);
                TextAnnotation annotation = await ReplaceAnnotation.GetAnnotationAsync(helper, documentName, annotationId, remoteFolder);

                annotation.Contents = helper.config.REPLACED_CONTENT;
                annotation.Icon = TextIcon.Star;

                TextAnnotationResponse response = await helper.pdfApi.PutTextAnnotationAsync(documentName, annotationId, annotation, folder: remoteFolder);
                if (response == null)
                    Console.WriteLine("ModifyAnnotation(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("ModifyAnnotation(): Failed to request text annotation from the document.");
                else
                {
                    Console.WriteLine("ModifyAnnotation(): annotation '{0}' successfully modified in the document '{1}.", annotationId, documentName);
                    await helper.DownloadFile(documentName, outputName, "replaced_annotatiom_");
                }
            }
        }
    }