C#でPDF注釈を追加および編集する方法

C#でPDFの注釈を追加して編集する方法

This article was translated from English: Does it need improvement?
Translated
View the article in English

注釈は、ユーザーがドキュメントの特定のセクションにコメント、リマインダー、または追加情報を追加できるようにします。 注釈は、PDFを使用する際のコラボレーションとコミュニケーションを強化し、ユーザーがコメントし、共有コンテンツにコンテキストを提供できるようにします。

クイックスタート: IronPDFを使用してPDFに注釈を追加

この簡単なガイドは、C#でIronPDFを使用してPDFドキュメントにテキスト注釈を簡単に追加する方法を示しています。 ほんの数行のコードで、開発者はPDFにコメントやノートを追加することで、ドキュメントのインタラクティビティとコラボレーションを向上させることができます。 PDFを読み込み、AddTextAnnotationメソッドを使用してすばやく注釈を挿入することから始めます。

Nuget Icon今すぐ NuGet で PDF を作成してみましょう:

  1. NuGet パッケージ マネージャーを使用して IronPDF をインストールします

    PM > Install-Package IronPdf

  2. このコード スニペットをコピーして実行します。

    PdfDocument.FromFile("input.pdf")
        .Annotations.Add(new TextAnnotation(0) { Title="Note", Contents="Review this section.", X=50, Y=700 })
        .SaveAs("annotated.pdf");
  3. 実際の環境でテストするためにデプロイする

    今すぐ無料トライアルでプロジェクトに IronPDF を使い始めましょう
    arrow pointer


注釈追加例

PDF注釈により、PDFページに "付箋" のようなコメントを追加することができます。 AnnotationsプロパティのAddメソッドを使用することで、プログラム的に注釈を追加することができます。

すべてのページインデックスはゼロベースのインデックスに従います。

:path=/static-assets/pdf/content-code-examples/how-to/annotation-add-annotation.cs
using IronPdf;
using IronPdf.Annotations;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>");

// Create a PDF annotation object on a specified page index
TextAnnotation annotation = new TextAnnotation(0)
{
    Title = "This is the title",
    Contents = "This is the long 'sticky note' comment content...",
    X = 50,
    Y = 700,
};

// Add the annotation
pdf.Annotations.Add(annotation);
pdf.SaveAs("annotation.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

注釈付きPDF

上記のPDFドキュメントの注釈はChromeブラウザーで表示できます。


注釈取得と編集例

PDF注釈の取得と編集は、明確さ、正確さ、使いやすさを向上させることでコラボレーションを改善します。 Annotationsプロパティを介して注釈コレクションにアクセスし、タイトル、内容、X、Yなどのプロパティを新しい情報で更新します。

:path=/static-assets/pdf/content-code-examples/how-to/annotation-edit-annotation.cs
using IronPdf;
using IronPdf.Annotations;
using System.Linq;

PdfDocument pdf = PdfDocument.FromFile("annotation.pdf");

// Retrieve annotation collection
PdfAnnotationCollection annotationCollection = pdf.Annotations;

// Select the first annotation
TextAnnotation annotation = (TextAnnotation)annotationCollection.First();

// Edit annotation
annotation.Title = "New title";
annotation.Contents = "New content...";
annotation.X = 150;
annotation.Y = 800;

pdf.SaveAs("editedAnnotation.pdf");
Imports IronPdf
Imports IronPdf.Annotations
Imports System.Linq

Private pdf As PdfDocument = PdfDocument.FromFile("annotation.pdf")

' Retrieve annotation collection
Private annotationCollection As PdfAnnotationCollection = pdf.Annotations

' Select the first annotation
Private annotation As TextAnnotation = CType(annotationCollection.First(), TextAnnotation)

' Edit annotation
annotation.Title = "New title"
annotation.Contents = "New content..."
annotation.X = 150
annotation.Y = 800

pdf.SaveAs("editedAnnotation.pdf")
$vbLabelText   $csharpLabel

編集された注釈付きPDF

上記のPDFドキュメントの注釈はChromeブラウザーで表示できます。


注釈削除例

以下の方法を使用して、不要な注釈や古い注釈を簡単に削除できます: RemoveAtRemoveAllAnnotationsForPage、およびClear

  • RemoveAt: 指定されたインデックスの単一の注釈を削除します。
  • RemoveAllAnnotationsForPage: 指定されたページ上のすべての注釈を削除します。
  • Clear: ドキュメント内のすべての注釈を削除します。

単一の注釈を削除

単一の注釈を削除するには、注釈コレクションインデックスに基づいて対応するインデックスを使用してRemoveAtメソッドを使用します。

:path=/static-assets/pdf/content-code-examples/how-to/annotation-remove-single-annotation.cs
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");

// Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1);

pdf.SaveAs("removeSingleAnnotation.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("multipleAnnotation.pdf")

' Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1)

pdf.SaveAs("removeSingleAnnotation.pdf")
$vbLabelText   $csharpLabel

PDFの単一注釈削除

上記のPDFドキュメントの注釈はChromeブラウザーで表示できます。

すべての注釈を削除

特定のページのすべての注釈を削除するには、RemoveAllAnnotationsForPageメソッドを使用し、ページインデックスを指定します。 ドキュメント全体のすべての注釈を削除したい場合は、AnnotationsプロパティのClearメソッドを単に呼び出してください。

:path=/static-assets/pdf/content-code-examples/how-to/annotation-remove-all-annotation.cs
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");

// Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0);

// Remove all annotaions on the document
pdf.Annotations.Clear();

pdf.SaveAs("removeAllAnnotation.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("multipleAnnotation.pdf")

' Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0)

' Remove all annotaions on the document
pdf.Annotations.Clear()

pdf.SaveAs("removeAllAnnotation.pdf")
$vbLabelText   $csharpLabel

次に何ができるのかを見てみましょうか? こちらのチュートリアルページをご覧ください: PDFの編集

よくある質問

C#でPDFに注釈を追加するにはどうすればいいですか?

C#でIronPDFを使用してPDFに注釈を追加できます。まず、PDF注釈用のC#ライブラリをダウンロードします。既存のPDFをロードするか、新しいPDF文書を作成して、AnnotationsプロパティのAddメソッドを使用してコメントやメモを挿入します。

C#を使用してPDF内の既存の注釈を編集するにはどうすればいいですか?

C#を使用してPDFの既存の注釈を編集するには、IronPDFのAnnotationsプロパティを通じて注釈コレクションにアクセスします。TitleやContents、X、Yなどのプロパティを新しい情報で更新して注釈を修正します。

C#を使用してPDFから注釈を削除する手順は何ですか?

IronPDFを使用してRemoveAtメソッドなどを用いて特定の注釈を削除し、RemoveAllAnnotationsForPageでページ上のすべての注釈をクリアし、Clearで文書からすべての注釈を削除することができます。

ウェブブラウザでPDFの注釈を表示できますか?

はい、IronPDFを使ってPDF文書に追加された注釈は、Chromeなどのウェブブラウザで表示できます。

PDF文書に注釈を追加するメリットは何ですか?

IronPDFを使用してPDF文書に注釈を追加することで、ユーザーがコメントやリマインダー、追加情報を付け加えることができ、コミュニケーションや共有コンテンツの文脈を向上させ、共同作業を強化します。

デジタル署名と暗号化サービスのドキュメントをどこで見つけられますか?

デジタル署名、秘匿化、暗号化、保護サービスのドキュメントは、IronSecureDocの公式ドキュメントページで見つけることができます:https://Iron Software.com/enterprise/securedoc/docs/。

PDF注釈を管理するためのC#メソッドには何がありますか?

IronPDFは、PDF注釈を管理するためのいくつかのC#メソッドを提供しています。具体的には、追加用のAdd、特定の注釈を削除するRemoveAt、すべての注釈をクリアするClearがあります。

注釈を操作する場合、IronPDF は .NET 10 と完全に互換性がありますか?

はい。IronPDF は .NET 10 と完全に互換性があり (設計による)、特別な回避策を必要とせずに、.NET 10 プロジェクトで通常どおり注釈操作 (追加、編集、削除) をサポートします。

Chaknith Bin
ソフトウェアエンジニア
ChaknithはIronXLとIronBarcodeに取り組んでいます。彼はC#と.NETの深い専門知識を持ち、ソフトウェアの改善や顧客サポートに貢献しています。ユーザーとの対話から得られる洞察が、より良い製品、ドキュメント、および全体的な経験に寄与しています。
準備はできましたか?
Nuget ダウンロード 16,493,056 | Version: 2025.11 リリース