C# を使って PDF 内のアノテーションを管理

PDF ドキュメント内の注釈の管理プログラムで PDF ファイルを変更するには、.NET の Aspose.PDF を使用してください

.NET ライブラリを使用して注釈を管理する方法

PDFファイルにテキスト注釈を追加するために、net プラットフォーム用の機能が豊富で強力で使いやすいドキュメント操作APIである Aspose.PDF for .NET APIを使用します。NuGet パッケージマネージャーを開き、Aspose.pdf を検索してインストールします。Package Manager コンソールから次のコマンドを使用することもできます。

Package Manager Console

PM > Install-Package Aspose.PDF

C# を介して PDF ドキュメントに注釈を作成します


お使いの環境でコードを試すには、Aspose.PDF for.NET が必要です。

  1. Document クラスのインスタンスにPDFをロードします。
  2. PDF に追加する注釈を作成します。
  3. 注釈を Page オブジェクトの Annotations コレクションに追加します。
  4. PDF ファイルを保存します。

PDF テキスト注釈-C#

Example: C#

var inputFile = Path.Combine(dataDir, "AddAnnotation.pdf");
var outputFile = Path.Combine(dataDir, "AddAnnotation_out.pdf");

var pdfDocument = new Aspose.Pdf.Document(inputFile);
var textAnnotation =
    new Aspose.Pdf.Annotations.TextAnnotation(pdfDocument.Pages[1],
    new Aspose.Pdf.Rectangle(200, 400, 400, 600))
    {
        Title = "Sample Annotation Title",
        Subject = "Sample Subject"
    };
textAnnotation.SetReviewState(Aspose.Pdf.Annotations.AnnotationState.Accepted,"user");
textAnnotation.Contents = "Sample contents for the annotation";
textAnnotation.Open = true;
textAnnotation.Icon = Aspose.Pdf.Annotations.TextIcon.Key;

var border = new Aspose.Pdf.Annotations.Border(textAnnotation)
{
    Width = 5,
    Dash = new Aspose.Pdf.Annotations.Dash(1, 1)
};
textAnnotation.Border = border;
textAnnotation.Rect =
    new Aspose.Pdf.Rectangle(200, 400, 400, 600);
pdfDocument.Pages[1].Annotations.Add(textAnnotation);
        
pdfDocument.Save(outputFile);